当前位置: 首页>>代码示例>>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;未经允许,请勿转载。