當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。