# Python numpy.unsignedinteger() Examples

The following are 30 code examples for showing how to use numpy.unsignedinteger(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
 Project: recruit   Author: Frank-qlu   File: test_umath.py    License: Apache License 2.0 6 votes
```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]) ```
Example 2
 Project: recruit   Author: Frank-qlu   File: test_umath.py    License: Apache License 2.0 6 votes
```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]) ```
Example 3
 Project: buzzard   Author: airware   File: file_checker.py    License: Apache License 2.0 6 votes
```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)

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()) ```
Example 4
 Project: buzzard   Author: airware   File: writer.py    License: Apache License 2.0 6 votes
```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)

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()) ```
Example 5
 Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 6
 Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 7
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 8
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 9
 Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_umath.py    License: Apache License 2.0 6 votes
```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]) ```
Example 10
 Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_umath.py    License: Apache License 2.0 6 votes
```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]) ```
Example 11
 Project: pySINDy   Author: luckystarufo   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 12
 Project: pySINDy   Author: luckystarufo   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 13
 Project: coffeegrindsize   Author: jgagneastro   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 14
 Project: coffeegrindsize   Author: jgagneastro   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 15
 Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda   Author: PacktPublishing   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 16
 Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda   Author: PacktPublishing   File: test_umath.py    License: MIT License 6 votes
```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]) ```
Example 17
```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]) ```
Example 18
```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]) ```
Example 19
 Project: recruit   Author: Frank-qlu   File: test_abc.py    License: Apache License 2.0 5 votes
```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)) ```
Example 20
 Project: recruit   Author: Frank-qlu   File: numeric.py    License: Apache License 2.0 5 votes
```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') ```
Example 21
 Project: lambda-packs   Author: ryfeus   File: measurements.py    License: MIT License 5 votes
```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 ```
Example 22
 Project: vnpy_crypto   Author: birforce   File: test_abc.py    License: MIT License 5 votes
```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)) ```
Example 23
 Project: vnpy_crypto   Author: birforce   File: numeric.py    License: MIT License 5 votes
```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') ```
Example 24
 Project: vnpy_crypto   Author: birforce   File: common.py    License: MIT License 5 votes
```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))) ```
Example 25
 Project: nufhe   Author: nucypher   File: operators_integer.py    License: GNU General Public License v3.0 5 votes
```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,)) ```
Example 26
 Project: Computable   Author: ktraunmueller   File: measurements.py    License: MIT License 5 votes
```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 ```
Example 27
 Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_abc.py    License: MIT License 5 votes
```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)) ```
Example 28
 Project: chainer   Author: chainer   File: test_cast.py    License: MIT License 5 votes
```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, ```
Example 29
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_abc.py    License: MIT License 5 votes
```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)) ```
Example 30
 Project: GraphicDesignPatternByPython   Author: Relph1119   File: test_base.py    License: MIT License 5 votes
```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,) ```