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


Python multiarray.dtype方法代码示例

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


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

示例1: _set_array_types

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _set_array_types():
    ibytes = [1, 2, 4, 8, 16, 32, 64]
    fbytes = [2, 4, 8, 10, 12, 16, 32, 64]
    for bytes in ibytes:
        bits = 8*bytes
        _add_array_type('int', bits)
        _add_array_type('uint', bits)
    for bytes in fbytes:
        bits = 8*bytes
        _add_array_type('float', bits)
        _add_array_type('complex', 2*bits)
    _gi = dtype('p')
    if _gi.type not in sctypes['int']:
        indx = 0
        sz = _gi.itemsize
        _lst = sctypes['int']
        while (indx < len(_lst) and sz >= _lst[indx](0).itemsize):
            indx += 1
        sctypes['int'].insert(indx, _gi.type)
        sctypes['uint'].insert(indx, dtype('P').type) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:_type_aliases.py

示例2: _mean

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
    arr = asanyarray(a)

    rcount = _count_reduce_items(arr, axis)
    # Make this warning show up first
    if rcount == 0:
        warnings.warn("Mean of empty slice.", RuntimeWarning)

    # Cast bool, unsigned int, and int to float64 by default
    if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
        dtype = mu.dtype('f8')

    ret = umr_sum(arr, axis, dtype, out, keepdims)
    if isinstance(ret, mu.ndarray):
        ret = um.true_divide(
                ret, rcount, out=ret, casting='unsafe', subok=False)
    elif hasattr(ret, 'dtype'):
        ret = ret.dtype.type(ret / rcount)
    else:
        ret = ret / rcount

    return ret 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:24,代码来源:_methods.py

示例3: _getintp_ctype

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _getintp_ctype():
    from .multiarray import dtype
    val = _getintp_ctype.cache
    if val is not None:
        return val
    char = dtype('p').char
    import ctypes
    if (char == 'i'):
        val = ctypes.c_int
    elif char == 'l':
        val = ctypes.c_long
    elif char == 'q':
        val = ctypes.c_longlong
    else:
        val = ctypes.c_long
    _getintp_ctype.cache = val
    return val 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:19,代码来源:_internal.py

示例4: test_column_subset_detect_empty

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def test_column_subset_detect_empty(self):
        """
        Tests that when ordered=False, validation is possible by
        passing a subset of the columns contained in the schema

        Schema         a                b* (validation)
        Data Frame     b (error)        a

        column* is not being passed

        There will be an error if other than zero errors are found.
        """

        df = pd.read_csv(StringIO('''
b,a
 1,1
2,3
3,3
        '''), sep=',', header=0, dtype=str)
        # should detect no errors
        results_empty = self.schema.validate(df, columns=['a'])

        self.assertEqual(len(results_empty), 0, 'There should be no errors') 
开发者ID:TMiguelT,项目名称:PandasSchema,代码行数:25,代码来源:test_schema.py

示例5: test_column_subset_error

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def test_column_subset_error(self):
        """
        Tests that when ordered=False, validation is possible by
        passing a subset of the columns contained in the schema

        Schema         a                b (validation)
        Data Frame     b (error)        a

        There will be an error if a column different than 'a' or 'b' is passed
        """

        df = pd.read_csv(StringIO('''
b,a
 1,1
2,3
3,3
        '''), sep=',', header=0, dtype=str)

        # should raise a PanSchArgumentError
        self.assertRaises(PanSchArgumentError, self.schema.validate, df, columns=['c']) 
开发者ID:TMiguelT,项目名称:PandasSchema,代码行数:22,代码来源:test_schema.py

示例6: test_mixed_columns

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def test_mixed_columns(self):
        """
        Tests that when ordered=True, the schema columns are associated with data frame columns by position, not name.

        In this case, the schema's column order is [a, b], while the data frame's order is [b, a]. There is an error in
        column b in the data frame (leading whitespace), and a validation on column a in the schema.

        Schema         a (validation)   b
        Data Frame     b (error)        a

        Thus there will only be an error if column b in the schema is linked to column a in the data frame,
        as is correct behaviour when ordered=True.
        """
        df = pd.read_csv(StringIO('''
b,a
 1,1
2,3
3,3
        '''), sep=',', header=0, dtype=str)
        results = self.schema.validate(df)

        self.assertEqual(len(results), 1, 'There should be 1 error')
        self.assertEqual(results[0].row, 0)
        self.assertEqual(results[0].column, 'b', 'The Schema object is not associating columns and column schemas by position') 
开发者ID:TMiguelT,项目名称:PandasSchema,代码行数:26,代码来源:test_schema.py

示例7: _bits_of

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _bits_of(obj):
    try:
        info = next(v for v in _concrete_typeinfo.values() if v.type is obj)
    except StopIteration:
        if obj in _abstract_types.values():
            raise ValueError("Cannot count the bits of an abstract type")

        # some third-party type - make a best-guess
        return dtype(obj).itemsize * 8
    else:
        return info.bits 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,代码来源:_type_aliases.py

示例8: bitname

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def bitname(obj):
    """Return a bit-width name for a given type object"""
    bits = _bits_of(obj)
    dt = dtype(obj)
    char = dt.kind
    base = _kind_name(dt)

    if base == 'object':
        bits = 0

    if bits != 0:
        char = "%s%d" % (char, bits // 8)

    return base, bits, char 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:16,代码来源:_type_aliases.py

示例9: _sum

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _sum(a, axis=None, dtype=None, out=None, keepdims=False,
         initial=_NoValue):
    return umr_sum(a, axis, dtype, out, keepdims, initial) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:_methods.py

示例10: _prod

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _prod(a, axis=None, dtype=None, out=None, keepdims=False,
          initial=_NoValue):
    return umr_prod(a, axis, dtype, out, keepdims, initial) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:_methods.py

示例11: _all

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _all(a, axis=None, dtype=None, out=None, keepdims=False):
    return umr_all(a, axis, dtype, out, keepdims) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:4,代码来源:_methods.py

示例12: _mean

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
    arr = asanyarray(a)

    is_float16_result = False
    rcount = _count_reduce_items(arr, axis)
    # Make this warning show up first
    if rcount == 0:
        warnings.warn("Mean of empty slice.", RuntimeWarning, stacklevel=2)

    # Cast bool, unsigned int, and int to float64 by default
    if dtype is None:
        if issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
            dtype = mu.dtype('f8')
        elif issubclass(arr.dtype.type, nt.float16):
            dtype = mu.dtype('f4')
            is_float16_result = True

    ret = umr_sum(arr, axis, dtype, out, keepdims)
    if isinstance(ret, mu.ndarray):
        ret = um.true_divide(
                ret, rcount, out=ret, casting='unsafe', subok=False)
        if is_float16_result and out is None:
            ret = arr.dtype.type(ret)
    elif hasattr(ret, 'dtype'):
        if is_float16_result:
            ret = arr.dtype.type(ret / rcount)
        else:
            ret = ret.dtype.type(ret / rcount)
    else:
        ret = ret / rcount

    return ret 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:34,代码来源:_methods.py

示例13: _std

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
               keepdims=keepdims)

    if isinstance(ret, mu.ndarray):
        ret = um.sqrt(ret, out=ret)
    elif hasattr(ret, 'dtype'):
        ret = ret.dtype.type(um.sqrt(ret))
    else:
        ret = um.sqrt(ret)

    return ret 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,代码来源:_methods.py

示例14: _any

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def _any(a, axis=None, dtype=None, out=None, keepdims=False):
    return umr_any(a, axis, dtype, out, keepdims) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:4,代码来源:_methods.py

示例15: ascontiguousarray

# 需要导入模块: from numpy.core import multiarray [as 别名]
# 或者: from numpy.core.multiarray import dtype [as 别名]
def ascontiguousarray(a, dtype=None):
    """
    Return a contiguous array in memory (C order).

    Parameters
    ----------
    a : array_like
        Input array.
    dtype : str or dtype object, optional
        Data-type of returned array.

    Returns
    -------
    out : ndarray
        Contiguous array of same shape and content as `a`, with type `dtype`
        if specified.

    See Also
    --------
    asfortranarray : Convert input to an ndarray with column-major
                     memory order.
    require : Return an ndarray that satisfies requirements.
    ndarray.flags : Information about the memory layout of the array.

    Examples
    --------
    >>> x = np.arange(6).reshape(2,3)
    >>> np.ascontiguousarray(x, dtype=np.float32)
    array([[ 0.,  1.,  2.],
           [ 3.,  4.,  5.]], dtype=float32)
    >>> x.flags['C_CONTIGUOUS']
    True

    """
    return array(a, dtype, copy=False, order='C', ndmin=1) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:37,代码来源:numeric.py


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