本文整理汇总了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])
示例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])
示例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())
示例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))
示例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')
示例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
示例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)))
示例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,))
示例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
示例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,
示例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,)