當前位置: 首頁>>代碼示例>>Python>>正文


Python builtins.xrange方法代碼示例

本文整理匯總了Python中past.builtins.xrange方法的典型用法代碼示例。如果您正苦於以下問題:Python builtins.xrange方法的具體用法?Python builtins.xrange怎麽用?Python builtins.xrange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在past.builtins的用法示例。


在下文中一共展示了builtins.xrange方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_chunks

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def get_chunks(df, chunksize=None):
    rows = len(df)
    if rows == 0:
        return
    if chunksize is None:
        chunksize = rows
    elif chunksize <= 0:
        raise ValueError("Chunk size argument must be greater than zero")

    chunks = int(rows / chunksize) + 1
    for i in xrange(chunks):
        start_i = i * chunksize
        end_i = min((i + 1) * chunksize, rows)
        if start_i >= end_i:
            break
        yield df[start_i:end_i] 
開發者ID:laughingman7743,項目名稱:PyAthena,代碼行數:18,代碼來源:util.py

示例2: _build_gadgets

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def _build_gadgets(self, gadget_tree_root):
        """Return a gadgets list.
        """
        node_list = self._build_gadgets_rec(gadget_tree_root)

        return [RawGadget(n) for n in node_list]

        # TODO: Update x86 gadgets tests before uncommenting the following.
        # (this change breaks x86 gadgets tests.)
        # gadgets = []

        # for node in node_list:
        #     for i in xrange(len(node)):
        #         gadgets.append(RawGadget(node[i:]))

        # return gadgets 
開發者ID:programa-stic,項目名稱:barf-project,代碼行數:18,代碼來源:finder.py

示例3: __get_python_indices_for_key

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def __get_python_indices_for_key(self, key, list_of_entries):
        '''
        Finds the indices of all entries that have a specific type. Important:
            This method finds the python indices of the list of entries! These
            are not the Handle System index values!

        :param key: The key (Handle Record type)
        :param list_of_entries: A list of the existing entries in which to find
            the indices.
        :return: A list of integers, the indices of the entries of type "key"
            in the given list.
        '''
        indices = []
        for i in xrange(len(list_of_entries)):
            if list_of_entries[i]['type'] == key:
                indices.append(i)
        return indices 
開發者ID:EUDAT-B2SAFE,項目名稱:B2HANDLE,代碼行數:19,代碼來源:handleclient.py

示例4: sort

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def sort(self):
        colcyc = itertools.cycle(list(self.palette))
        palcyc = [next(colcyc) for _ in xrange(len(self.x))]
        if self.order == 'x':
            self.ordr = np.array([self.x[i] for i in self.x.argsort()])
            self.palette = sns.color_palette(
                [palcyc[i] for i in self.x.argsort()])
        elif self.order == 'y':
            self.ordr = np.array([self.x[i] for i in self.y.argsort()])
            self.palette = sns.color_palette(
                [palcyc[i] for i in self.y.argsort()])
        elif len(set(self.order) & set(self.x)) == len(self.x):
            self.ordr = np.array(self.order)
            xl = list(self.x)
            self.palette = sns.color_palette(
                [palcyc[xl.index(i)] for i in self.ordr])
        else:
            self.ordr = self.x
        if self.desc:
            self.ordr = self.ordr[::-1]
            self.palette = sns.color_palette(list(self.palette)[::-1]) 
開發者ID:saezlab,項目名稱:pypath,代碼行數:23,代碼來源:plot.py

示例5: htp_calculations

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def htp_calculations(self):
        if not len(self.htdata):
            self.refc = collections.Counter(
                common.flat_list((r.pmid for r in e['references'])
                                for e in self.pp.graph.es))

            # percentage of high throughput interactions
            htsrcs_prev = set(self.pp.sources)
            self.prg = progress.Progress(self.upper - self.lower,
                                         'Analysing HTP refs/interactions', 1)
            for htlim in reversed(xrange(self.lower, self.upper + 1)):
                self.prg.step()
                self.get_point(htlim)
                htsrcs_new = self.htdata[htlim]['htsrcs']
                diff = htsrcs_new - htsrcs_prev
                htsrcs_prev = htsrcs_new
                if len(diff):
                    sys.stdout.write(
                        '\n\t:: %s: no references with more interaction than %u\n'
                        % (', '.join(list(diff)), htlim - 1))
                    sys.stdout.flush() 
開發者ID:saezlab,項目名稱:pypath,代碼行數:23,代碼來源:plot.py

示例6: gen_session_id

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def gen_session_id(length=5):
    """Generates a random alphanumeric string.

    :arg int length:
        Optional, ``5`` by default. Specifies the length of the random
        string.

    :return:
        (*str*) -- Random alphanumeric string of the specified length.
    """

    abc = '0123456789abcdefghijklmnopqrstuvwxyz'

    return ''.join(random.choice(abc) for i in xrange(length))


# XXX: Are you sure this is the way to compute Simpson's index? 
開發者ID:saezlab,項目名稱:pypath,代碼行數:19,代碼來源:common.py

示例7: get_proteins

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def get_proteins(self,
                     tissue_id,
                     calculation_method=0,
                     swissprot_only=1,
                     no_isoform=1):
        '''
        '''
        for i in xrange(3):
            
            self.query(
                'proteinpertissue',
                (tissue_id, calculation_method, swissprot_only, no_isoform,
                 self.output_format),
                large=True)
            
            if hasattr(self.result, 'read'):
                break 
開發者ID:saezlab,項目名稱:pypath,代碼行數:19,代碼來源:proteomicsdb.py

示例8: file_write

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def file_write(self, handle, data):
        MAXIMUM_WRITE_SIZE = 1 << 15
        hh = struct.pack("<Q", handle)
        segments = int(len(data) / MAXIMUM_WRITE_SIZE)
        try:
            for i in xrange(segments):
                self.dispatch_packet(AFC_OP_WRITE,
                                 hh + data[i*MAXIMUM_WRITE_SIZE:(i+1)*MAXIMUM_WRITE_SIZE],
                                     this_length=48)
                s, d = self.receive_data()
                if s != AFC_E_SUCCESS:
                    self.logger.error("file_write error: %d", s)
                    break
            if len(data) % MAXIMUM_WRITE_SIZE:
                self.dispatch_packet(AFC_OP_WRITE,
                                     hh + data[segments*MAXIMUM_WRITE_SIZE:],
                                     this_length=48)
                s, d = self.receive_data()
        except:
            self.lockdown = LockdownClient()
            self.service = self.lockdown.startService(self.serviceName)
            self.file_write(handle,data)
        return s 
開發者ID:iOSForensics,項目名稱:pymobiledevice,代碼行數:25,代碼來源:afc.py

示例9: test_s_mirror

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def test_s_mirror(self):
        test_group_values = [b"a", b"bb", b"ccc", b"dddd"]
        s_initialize("test_s_mirror")

        s_size("data", output_format="ascii", fuzzable=False, name="size")
        s_mirror("size", name="size_mirror")

        with s_block("data"):
            s_static("<")
            s_group("group_start", values=test_group_values)
            s_static(">")
            s_static("hello")
            s_static("</")
            s_mirror("group_start", name="group_end")
            s_static(">")

        req = s_get("test_s_mirror")
        for _ in xrange(len(test_group_values)):
            s_mutate()
            group_start_value = req.names["group_start"].render()
            self.assertEqual(
                int(req.names["size"].render()), len("<{0}>hello</{0}>".format(group_start_value.decode("utf-8")))
            )
            self.assertEqual(req.names["group_end"].render(), group_start_value)
            self.assertEqual(req.names["size_mirror"].render(), req.names["size"].render()) 
開發者ID:jtpereyda,項目名稱:boofuzz,代碼行數:27,代碼來源:test_primitives.py

示例10: find_ints

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def find_ints(start_address):
    constants = []

    # loop heads
    for head in Heads(start_address, SegEnd(start_address)):

        # if it's code, check for cmp instruction
        if isCode(GetFlags(head)):
            mnem = GetMnem(head)
            op1 = int(GetOperandValue(head, 1))

            # if it's a cmp and it's immediate value is unique, add it to the list
            if "cmp" in mnem and op1 not in constants:
                constants.append(op1)

    print("Found %d constant values used in compares." % len(constants))
    print("-----------------------------------------------------")
    for i in xrange(0, len(constants), 20):
        print(constants[i : i + 20])

    return constants 
開發者ID:jtpereyda,項目名稱:boofuzz,代碼行數:23,代碼來源:ida_fuzz_library_extender.py

示例11: nonzero

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def nonzero(self):
        """
        Get all non-zero bits
        """
        return [i for i in xrange(self.size()) if self.test(i)] 
開發者ID:wanji,項目名稱:bitmap,代碼行數:7,代碼來源:bitmap.py

示例12: fromstring

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def fromstring(cls, bitstring):
        """
        Construct BitMap from string
        """
        nbits = len(bitstring)
        bm = cls(nbits)
        for i in xrange(nbits):
            if bitstring[-i-1] == '1':
                bm.set(i)
            elif bitstring[-i-1] != '0':
                raise Exception("Invalid bit string!")
        return bm 
開發者ID:wanji,項目名稱:bitmap,代碼行數:14,代碼來源:bitmap.py

示例13: test_count

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def test_count(self):
        """ Test BitMap: create
        """
        for bitstr in self.v_str:
            bm = BitMap.fromstring(bitstr)
            self.assertEqual(bitstr.count("1"), bm.count())
            self.assertEqual(bitstr.count("1"),
                             len([i for i in xrange(bm.size()) if bm.test(i)]))

        for bitstr in self.v_str[:-4]:
            self.assertTrue(BitMap.fromstring(bitstr).any())
        self.assertTrue(BitMap.fromstring(self.v_str[-2]).all())
        self.assertTrue(BitMap.fromstring(self.v_str[-1]).none()) 
開發者ID:wanji,項目名稱:bitmap,代碼行數:15,代碼來源:test_bitmap.py

示例14: create_matrix_block_indices

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def create_matrix_block_indices(row_to_obs):
    """
    Parameters
    ----------
    row_to_obs: 2D ndarray.
        There should be one row per observation per available alternative and
        one column per observation. This matrix maps the rows of the design
        matrix to the unique observations (on the columns).

    Returns
    -------
    output_indices : list of arrays.
        There will be one array per column in `row_to_obs`. The array will note
        which rows correspond to which observations.
    """
    # Initialize the list of index arrays to be returned
    output_indices = []
    # Determine the number of observations in the dataset
    num_obs = row_to_obs.shape[1]
    # Get the indices of the non-zero elements and their values
    row_indices, col_indices, values = scipy.sparse.find(row_to_obs)
    # Iterate over each observation, i.e. each column in row_to_obs, and
    # determine which rows belong to that observation (i.e. the rows with ones
    # in them).
    for col in xrange(num_obs):
        # Store the array of row indices belonging to the current observation
        output_indices.append(row_indices[np.where(col_indices == col)])

    return output_indices 
開發者ID:timothyb0912,項目名稱:pylogit,代碼行數:31,代碼來源:choice_calcs.py

示例15: generate_grid

# 需要導入模塊: from past import builtins [as 別名]
# 或者: from past.builtins import xrange [as 別名]
def generate_grid(self):
        """Generate the grid of hyperparameter value combinations"""

        options = dict(self.options)
        params = {}

        # Remove 'p' to hold as a constant in the paramater combinations
        p = options.pop("p")
        params["p"] = [p for _ in xrange(self.n_selection_iters)]

        # Assign generators based on parameter type
        param_generators = {
            "c1": np.random.uniform,
            "c2": np.random.uniform,
            "w": np.random.uniform,
            "k": np.random.randint,
        }

        # Generate random values for hyperparameters 'c1', 'c2', 'w', and 'k'
        for idx, bounds in options.items():
            params[idx] = param_generators[idx](
                *bounds, size=self.n_selection_iters
            )

        # Return list of dicts of hyperparameter combinations
        return [
            {
                "c1": params["c1"][i],
                "c2": params["c2"][i],
                "w": params["w"][i],
                "k": params["k"][i],
                "p": params["p"][i],
            }
            for i in xrange(self.n_selection_iters)
        ] 
開發者ID:ljvmiranda921,項目名稱:pyswarms,代碼行數:37,代碼來源:random_search.py


注:本文中的past.builtins.xrange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。