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


Python numpy.unsignedinteger方法代碼示例

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


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

示例1: _test_lcm_inner

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _test_lcm_inner(self, dtype):
        # basic use
        a = np.array([12, 120], dtype=dtype)
        b = np.array([20, 200], dtype=dtype)
        assert_equal(np.lcm(a, b), [60, 600])

        if not issubclass(dtype, np.unsignedinteger):
            # negatives are ignored
            a = np.array([12, -12,  12, -12], dtype=dtype)
            b = np.array([20,  20, -20, -20], dtype=dtype)
            assert_equal(np.lcm(a, b), [60]*4)

        # reduce
        a = np.array([3, 12, 20], dtype=dtype)
        assert_equal(np.lcm.reduce([3, 12, 20]), 60)

        # broadcasting, and a test including 0
        a = np.arange(6).astype(dtype)
        b = 20
        assert_equal(np.lcm(a, b), [0, 20, 20, 60, 20, 20]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:test_umath.py

示例2: _test_gcd_inner

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _test_gcd_inner(self, dtype):
        # basic use
        a = np.array([12, 120], dtype=dtype)
        b = np.array([20, 200], dtype=dtype)
        assert_equal(np.gcd(a, b), [4, 40])

        if not issubclass(dtype, np.unsignedinteger):
            # negatives are ignored
            a = np.array([12, -12,  12, -12], dtype=dtype)
            b = np.array([20,  20, -20, -20], dtype=dtype)
            assert_equal(np.gcd(a, b), [4]*4)

        # reduce
        a = np.array([15, 25, 35], dtype=dtype)
        assert_equal(np.gcd.reduce(a), 5)

        # broadcasting, and a test including 0
        a = np.arange(6).astype(dtype)
        b = 20
        assert_equal(np.gcd(a, b), [20,  1,  2,  1,  4,  5]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:22,代碼來源:test_umath.py

示例3: _checksum

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _checksum(fname, buffer_size=512 * 1024, dtype='uint64'):
    # https://github.com/airware/buzzard/pull/39/#discussion_r239071556
    dtype = np.dtype(dtype)
    dtypesize = dtype.itemsize
    assert buffer_size % dtypesize == 0
    assert np.issubdtype(dtype, np.unsignedinteger)

    acc = dtype.type(0)
    with open(fname, "rb") as f:
        with np.warnings.catch_warnings():
            np.warnings.filterwarnings('ignore', r'overflow encountered')

            for chunk in iter(lambda: f.read(buffer_size), b""):
                head = np.frombuffer(chunk, dtype, count=len(chunk) // dtypesize)
                head = np.add.reduce(head, dtype=dtype, initial=acc)
                acc += head

                tailsize = len(chunk) % dtypesize
                if tailsize > 0:
                    # This should only be needed for file's tail
                    tail = chunk[-tailsize:] + b'\0' * (dtypesize - tailsize)
                    tail = np.frombuffer(tail, dtype)
                    acc += tail
        return '{:016x}'.format(acc.item()) 
開發者ID:airware,項目名稱:buzzard,代碼行數:26,代碼來源:file_checker.py

示例4: test_abstract

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def test_abstract(self):
        assert_(issubclass(np.number, numbers.Number))

        assert_(issubclass(np.inexact, numbers.Complex))
        assert_(issubclass(np.complexfloating, numbers.Complex))
        assert_(issubclass(np.floating, numbers.Real))

        assert_(issubclass(np.integer, numbers.Integral))
        assert_(issubclass(np.signedinteger, numbers.Integral))
        assert_(issubclass(np.unsignedinteger, numbers.Integral)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:12,代碼來源:test_abc.py

示例5: _assert_safe_casting

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _assert_safe_casting(cls, data, subarr):
        """
        Ensure incoming data can be represented as uints.
        """
        if not issubclass(data.dtype.type, np.unsignedinteger):
            if not np.array_equal(data, subarr):
                raise TypeError('Unsafe NumPy casting, you must '
                                'explicitly cast') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:numeric.py

示例6: _safely_castable_to_int

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _safely_castable_to_int(dt):
    """Test whether the numpy data type `dt` can be safely cast to an int."""
    int_size = np.dtype(int).itemsize
    safe = ((np.issubdtype(dt, np.signedinteger) and dt.itemsize <= int_size) or
            (np.issubdtype(dt, np.unsignedinteger) and dt.itemsize < int_size))
    return safe 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:8,代碼來源:measurements.py

示例7: is_unsigned_integer_dtype

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def is_unsigned_integer_dtype(arr_or_dtype):
    """
    Check whether the provided array or dtype is of an unsigned integer dtype.

    Parameters
    ----------
    arr_or_dtype : array-like
        The array or dtype to check.

    Returns
    -------
    boolean : Whether or not the array or dtype is of an
              unsigned integer dtype.

    Examples
    --------
    >>> is_unsigned_integer_dtype(str)
    False
    >>> is_unsigned_integer_dtype(int)  # signed
    False
    >>> is_unsigned_integer_dtype(float)
    False
    >>> is_unsigned_integer_dtype(np.uint64)
    True
    >>> is_unsigned_integer_dtype(np.array(['a', 'b']))
    False
    >>> is_unsigned_integer_dtype(pd.Series([1, 2]))  # signed
    False
    >>> is_unsigned_integer_dtype(pd.Index([1, 2.]))  # float
    False
    >>> is_unsigned_integer_dtype(np.array([1, 2], dtype=np.uint32))
    True
    """

    if arr_or_dtype is None:
        return False
    tipo = _get_dtype_type(arr_or_dtype)
    return (issubclass(tipo, np.unsignedinteger) and
            not issubclass(tipo, (np.datetime64, np.timedelta64))) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:41,代碼來源:common.py

示例8: uintarray_to_bitarray

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def uintarray_to_bitarray(xs, itemsize=None):
    if itemsize is None:
        itemsize = xs.itemsize * 8
    assert numpy.issubdtype(xs.dtype, numpy.unsignedinteger)
    res = numpy.vstack(_uint_to_bits(x, itemsize) for x in xs.flatten())
    return res.reshape(xs.shape + (itemsize,)) 
開發者ID:nucypher,項目名稱:nufhe,代碼行數:8,代碼來源:operators_integer.py

示例9: _safely_castable_to_int

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _safely_castable_to_int(dt):
    """Test whether the numpy data type `dt` can be safely cast to an int."""
    int_size = np.dtype(int).itemsize
    safe = ((np.issubdtype(dt, int) and dt.itemsize <= int_size) or
            (np.issubdtype(dt, np.unsignedinteger) and dt.itemsize < int_size))
    return safe 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:measurements.py

示例10: generate_inputs

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def generate_inputs(self):
        x = numpy.asarray(numpy.random.randn(*self.shape)).astype(self.in_type)
        # The result of a cast from a negative floating-point number to
        # an unsigned integer is not specified. Avoid testing that condition.
        float_to_uint = (
            issubclass(self.in_type, numpy.floating)
            and issubclass(self.out_type, numpy.unsignedinteger))
        if float_to_uint:
            x[x < 0] *= -1
        return x, 
開發者ID:chainer,項目名稱:chainer,代碼行數:12,代碼來源:test_cast.py

示例11: _same_sum_duplicate

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import unsignedinteger [as 別名]
def _same_sum_duplicate(data, *inds, **kwargs):
    """Duplicates entries to produce the same matrix"""
    indptr = kwargs.pop('indptr', None)
    if np.issubdtype(data.dtype, np.bool_) or \
       np.issubdtype(data.dtype, np.unsignedinteger):
        if indptr is None:
            return (data,) + inds
        else:
            return (data,) + inds + (indptr,)

    zeros_pos = (data == 0).nonzero()

    # duplicate data
    data = data.repeat(2, axis=0)
    data[::2] -= 1
    data[1::2] = 1

    # don't spoil all explicit zeros
    if zeros_pos[0].size > 0:
        pos = tuple(p[0] for p in zeros_pos)
        pos1 = (2*pos[0],) + pos[1:]
        pos2 = (2*pos[0]+1,) + pos[1:]
        data[pos1] = 0
        data[pos2] = 0

    inds = tuple(indices.repeat(2) for indices in inds)

    if indptr is None:
        return (data,) + inds
    else:
        return (data,) + inds + (indptr * 2,) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:33,代碼來源:test_base.py


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