当前位置: 首页>>代码示例>>Python>>正文


Python numpy.record方法代码示例

本文整理汇总了Python中numpy.record方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.record方法的具体用法?Python numpy.record怎么用?Python numpy.record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.record方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_recarray_repr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_recarray_repr(self):
        a = np.array([(1, 0.1), (2, 0.2)],
                     dtype=[('foo', '<i4'), ('bar', '<f8')])
        a = np.rec.array(a)
        assert_equal(
            repr(a),
            textwrap.dedent("""\
            rec.array([(1, 0.1), (2, 0.2)],
                      dtype=[('foo', '<i4'), ('bar', '<f8')])""")
        )

        # make sure non-structured dtypes also show up as rec.array
        a = np.array(np.ones(4, dtype='f8'))
        assert_(repr(np.rec.array(a)).startswith('rec.array'))

        # check that the 'np.record' part of the dtype isn't shown
        a = np.rec.array(np.ones(3, dtype='i4,i4'))
        assert_equal(repr(a).find('numpy.record'), -1)
        a = np.rec.array(np.ones(3, dtype='i4'))
        assert_(repr(a).find('dtype=int32') != -1) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_records.py

示例2: test_recarray_from_repr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_recarray_from_repr(self):
        a = np.array([(1,'ABC'), (2, "DEF")],
                     dtype=[('foo', int), ('bar', 'S4')])
        recordarr = np.rec.array(a)
        recarr = a.view(np.recarray)
        recordview = a.view(np.dtype((np.record, a.dtype)))

        recordarr_r = eval("numpy." + repr(recordarr), {'numpy': np})
        recarr_r = eval("numpy." + repr(recarr), {'numpy': np})
        recordview_r = eval("numpy." + repr(recordview), {'numpy': np})

        assert_equal(type(recordarr_r), np.recarray)
        assert_equal(recordarr_r.dtype.type, np.record)
        assert_equal(recordarr, recordarr_r)

        assert_equal(type(recarr_r), np.recarray)
        assert_equal(recarr_r.dtype.type, np.record)
        assert_equal(recarr, recarr_r)

        assert_equal(type(recordview_r), np.ndarray)
        assert_equal(recordview.dtype.type, np.record)
        assert_equal(recordview, recordview_r) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_records.py

示例3: groups_to_bool

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def groups_to_bool(adata, groups, groupby=None):
    groups, groupby = get_groups(adata, groups, groupby)
    if isinstance(groups, (list, tuple, np.ndarray, np.record)):
        if groupby is not None and isinstance(groups[0], str):
            groups = np.array([key in groups for key in adata.obs[groupby]])

    if groupby is not None and groupby in adata.obs.keys():
        c = adata.obs[groupby]
        if np.any(pd.isnull(c)):
            valid = np.array(~pd.isnull(c))
            groups = (
                valid if groups is None or len(groups) != len(c) else groups & valid
            )

    groups = (
        np.ravel(groups)
        if isinstance(groups, (list, tuple, np.ndarray, np.record))
        else None
    )
    return groups 
开发者ID:theislab,项目名称:scvelo,代码行数:22,代码来源:utils.py

示例4: __new__

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def __new__(cls, shape=None, dtype=None, order='C'):
        dt = np.dtype(
            [
                ('kwargs', object),
                ('net_profit_abs', float),
                ('net_profit_perc', float),
                ('year_profit', float),
                ('win_average_profit_perc', float),
                ('loss_average_profit_perc', float),
                ('max_drawdown_abs', float),
                ('total_trades', int),
                ('win_trades_abs', int),
                ('win_trades_perc', float),
                ('profit_factor', float),
                ('recovery_factor', float),
                ('payoff_ratio', float),
            ]
        )
        shape = shape or (1,)
        return np.ndarray.__new__(cls, shape, (np.record, dt), order=order) 
开发者ID:constverum,项目名称:Quantdom,代码行数:22,代码来源:performance.py

示例5: test_repack_fields

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_repack_fields(self):
        dt = np.dtype('u1,f4,i8', align=True)
        a = np.zeros(2, dtype=dt)

        assert_equal(repack_fields(dt), np.dtype('u1,f4,i8'))
        assert_equal(repack_fields(a).itemsize, 13)
        assert_equal(repack_fields(repack_fields(dt), align=True), dt)

        # make sure type is preserved
        dt = np.dtype((np.record, dt))
        assert_(repack_fields(dt).type is np.record) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:test_recfunctions.py

示例6: _view_is_safe

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def _view_is_safe(oldtype, newtype):
    """ Checks safety of a view involving object arrays, for example when
    doing::

        np.zeros(10, dtype=oldtype).view(newtype)

    Parameters
    ----------
    oldtype : data-type
        Data type of original ndarray
    newtype : data-type
        Data type of the view

    Raises
    ------
    TypeError
        If the new type is incompatible with the old type.

    """

    # if the types are equivalent, there is no problem.
    # for example: dtype((np.record, 'i4,i4')) == dtype((np.void, 'i4,i4'))
    if oldtype == newtype:
        return

    if newtype.hasobject or oldtype.hasobject:
        raise TypeError("Cannot change data-type for object array.")
    return

# Given a string containing a PEP 3118 format specifier,
# construct a NumPy dtype 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:33,代码来源:_internal.py

示例7: test_0d_recarray_repr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_0d_recarray_repr(self):
        arr_0d = np.rec.array((1, 2.0, '2003'), dtype='<i4,<f8,<M8[Y]')
        assert_equal(repr(arr_0d), textwrap.dedent("""\
            rec.array((1, 2., '2003'),
                      dtype=[('f0', '<i4'), ('f1', '<f8'), ('f2', '<M8[Y]')])"""))

        record = arr_0d[()]
        assert_equal(repr(record), "(1, 2., '2003')")
        # 1.13 converted to python scalars before the repr
        try:
            np.set_printoptions(legacy='1.13')
            assert_equal(repr(record), '(1, 2.0, datetime.date(2003, 1, 1))')
        finally:
            np.set_printoptions(legacy=False) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:test_records.py

示例8: test_recarray_returntypes

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_recarray_returntypes(self):
        qux_fields = {'C': (np.dtype('S5'), 0), 'D': (np.dtype('S5'), 6)}
        a = np.rec.array([('abc ', (1,1), 1, ('abcde', 'fgehi')),
                          ('abc', (2,3), 1, ('abcde', 'jklmn'))],
                         dtype=[('foo', 'S4'),
                                ('bar', [('A', int), ('B', int)]),
                                ('baz', int), ('qux', qux_fields)])
        assert_equal(type(a.foo), np.ndarray)
        assert_equal(type(a['foo']), np.ndarray)
        assert_equal(type(a.bar), np.recarray)
        assert_equal(type(a['bar']), np.recarray)
        assert_equal(a.bar.dtype.type, np.record)
        assert_equal(type(a['qux']), np.recarray)
        assert_equal(a.qux.dtype.type, np.record)
        assert_equal(dict(a.qux.dtype.fields), qux_fields)
        assert_equal(type(a.baz), np.ndarray)
        assert_equal(type(a['baz']), np.ndarray)
        assert_equal(type(a[0].bar), np.record)
        assert_equal(type(a[0]['bar']), np.record)
        assert_equal(a[0].bar.A, 1)
        assert_equal(a[0].bar['A'], 1)
        assert_equal(a[0]['bar'].A, 1)
        assert_equal(a[0]['bar']['A'], 1)
        assert_equal(a[0].qux.D, b'fgehi')
        assert_equal(a[0].qux['D'], b'fgehi')
        assert_equal(a[0]['qux'].D, b'fgehi')
        assert_equal(a[0]['qux']['D'], b'fgehi') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:29,代码来源:test_records.py

示例9: test_equivalent_record

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_equivalent_record(self):
        """Test whether equivalent record dtypes hash the same."""
        a = np.dtype([('yo', int)])
        b = np.dtype([('yo', int)])
        assert_dtype_equal(a, b) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_dtype.py

示例10: test_void_subclass_unsized

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_void_subclass_unsized(self):
        dt = np.dtype(np.record)
        assert_equal(repr(dt), "dtype('V')")
        assert_equal(str(dt), '|V0')
        assert_equal(dt.name, 'record') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_dtype.py

示例11: test_void_subclass_sized

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_void_subclass_sized(self):
        dt = np.dtype((np.record, 2))
        assert_equal(repr(dt), "dtype('V2')")
        assert_equal(str(dt), '|V2')
        assert_equal(dt.name, 'record16') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_dtype.py

示例12: test_void_subclass_fields

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_void_subclass_fields(self):
        dt = np.dtype((np.record, [('a', '<u2')]))
        assert_equal(repr(dt), "dtype((numpy.record, [('a', '<u2')]))")
        assert_equal(str(dt), "(numpy.record, [('a', '<u2')])")
        assert_equal(dt.name, 'record16') 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,代码来源:test_dtype.py

示例13: test_recarray_repr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_recarray_repr(self):
        # make sure non-structured dtypes also show up as rec.array
        a = np.array(np.ones(4, dtype='f8'))
        assert_(repr(np.rec.array(a)).startswith('rec.array'))

        # check that the 'np.record' part of the dtype isn't shown
        a = np.rec.array(np.ones(3, dtype='i4,i4'))
        assert_equal(repr(a).find('numpy.record'), -1)
        a = np.rec.array(np.ones(3, dtype='i4'))
        assert_(repr(a).find('dtype=int32') != -1) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:12,代码来源:test_records.py

示例14: test_recarray_returntypes

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import record [as 别名]
def test_recarray_returntypes(self):
        qux_fields = {'C': (np.dtype('S5'), 0), 'D': (np.dtype('S5'), 6)}
        a = np.rec.array([('abc ', (1,1), 1, ('abcde', 'fgehi')),
                          ('abc', (2,3), 1, ('abcde', 'jklmn'))],
                         dtype=[('foo', 'S4'),
                                ('bar', [('A', int), ('B', int)]),
                                ('baz', int), ('qux', qux_fields)])
        assert_equal(type(a.foo), np.ndarray)
        assert_equal(type(a['foo']), np.ndarray)
        assert_equal(type(a.bar), np.recarray)
        assert_equal(type(a['bar']), np.recarray)
        assert_equal(a.bar.dtype.type, np.record)
        assert_equal(type(a['qux']), np.recarray)
        assert_equal(a.qux.dtype.type, np.record)
        assert_equal(dict(a.qux.dtype.fields), qux_fields)
        assert_equal(type(a.baz), np.ndarray)
        assert_equal(type(a['baz']), np.ndarray)
        assert_equal(type(a[0].bar), np.record)
        assert_equal(type(a[0]['bar']), np.record)
        assert_equal(a[0].bar.A, 1)
        assert_equal(a[0].bar['A'], 1)
        assert_equal(a[0]['bar'].A, 1)
        assert_equal(a[0]['bar']['A'], 1)
        assert_equal(a[0].qux.D, asbytes('fgehi'))
        assert_equal(a[0].qux['D'], asbytes('fgehi'))
        assert_equal(a[0]['qux'].D, asbytes('fgehi'))
        assert_equal(a[0]['qux']['D'], asbytes('fgehi')) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:29,代码来源:test_records.py


注:本文中的numpy.record方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。