本文整理汇总了Python中numpy.ulonglong方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.ulonglong方法的具体用法?Python numpy.ulonglong怎么用?Python numpy.ulonglong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.ulonglong方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _unsigned_subtract
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def _unsigned_subtract(a, b):
"""
Subtract two values where a >= b, and produce an unsigned result
This is needed when finding the difference between the upper and lower
bound of an int16 histogram
"""
# coerce to a single type
signed_to_unsigned = {
np.byte: np.ubyte,
np.short: np.ushort,
np.intc: np.uintc,
np.int_: np.uint,
np.longlong: np.ulonglong
}
dt = np.result_type(a, b)
try:
dt = signed_to_unsigned[dt.type]
except KeyError:
return np.subtract(a, b, dtype=dt)
else:
# we know the inputs are integers, and we are deliberately casting
# signed to unsigned
return np.subtract(a, b, casting='unsafe', dtype=dt)
示例2: _unsigned_subtract
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def _unsigned_subtract(a, b):
"""
Subtract two values where a >= b, and produce an unsigned result
This is needed when finding the difference between the upper and lower
bound of an int16 histogram
"""
# coerce to a single type
signed_to_unsigned = {
np.byte: np.ubyte,
np.short: np.ushort,
np.intc: np.uintc,
np.int_: np.uint,
np.longlong: np.ulonglong
}
dt = np.result_type(a, b)
try:
dt = signed_to_unsigned[dt.type]
except KeyError: # pragma: no cover
return np.subtract(a, b, dtype=dt)
else:
# we know the inputs are integers, and we are deliberately casting
# signed to unsigned
return np.subtract(a, b, casting='unsafe', dtype=dt)
示例3: scatter_add
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def scatter_add(a, slices, b):
"""Adds given values to specified elements of an array.
This function adds ``b`` to the specified elements of the copy of
``a``, and returns the copy.
The value of the original ``a`` is not changed.
Args:
a (:class:`~chainer.Variable` or :ref:`ndarray`): A variable.
slices (int, slice, Ellipsis, None, integer array-like, boolean\
array-like or tuple of them):
It is an integer, a slice, an ellipsis,
a numpy.newaxis, an integer array-like, a boolean array-like
or tuple of them.
b (:class:`~chainer.Variable` or :ref:`ndarray`):
A variable that is scatter added to ``a``.
Its shape has to equal ``a[slices]`` because broadcasting
of variables is not supported.
Returns:
A :class:`~chainer.Variable` object which is the result of
scatter addition.
.. note::
It only supports types that are supported by CUDA's atomicAdd when
an integer array is included in ``slices``.
The supported types are ``numpy.float32``, ``numpy.int32``,
``numpy.uint32``, ``numpy.uint64`` and ``numpy.ulonglong``.
.. note::
It does not support ``slices`` that contains multiple boolean arrays.
.. seealso::
:func:`numpy.add.at` and
:func:`cupyx.scatter_add`.
"""
y, = ScatterAdd(slices).apply((a, b))
return y
示例4: test_numpy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def test_numpy(self):
"""NumPy objects get serialized to readable JSON."""
l = [
np.float32(12.5),
np.float64(2.0),
np.float16(0.5),
np.bool(True),
np.bool(False),
np.bool_(True),
np.unicode_("hello"),
np.byte(12),
np.short(12),
np.intc(-13),
np.int_(0),
np.longlong(100),
np.intp(7),
np.ubyte(12),
np.ushort(12),
np.uintc(13),
np.ulonglong(100),
np.uintp(7),
np.int8(1),
np.int16(3),
np.int32(4),
np.int64(5),
np.uint8(1),
np.uint16(3),
np.uint32(4),
np.uint64(5),
]
l2 = [l, np.array([1, 2, 3])]
roundtripped = loads(dumps(l2, cls=EliotJSONEncoder))
self.assertEqual([l, [1, 2, 3]], roundtripped)
示例5: test_return_arrcrt_zeros
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def test_return_arrcrt_zeros(a, b, c):
d = np.zeros(3)
d[:] = 2
d[0] = 1
return d
# TODO: fix for np.ulonglong, np.longlong and uint64
示例6: test_return_scalar
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def test_return_scalar(dtype):
def fkt(a): return a
ao, ah = random(dtype, [])
ro, rh = fkt(ao), hope.jit(fkt)(ah)
assert check(ro, rh)
# TODO: fix for np.ulonglong, np.longlong and uint64
示例7: test_return_arrayscalar
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def test_return_arrayscalar(dtype):
def fkt(a): return a[2]
ao, ah = random(dtype, [10])
ro, rh = fkt(ao), hope.jit(fkt)(ah)
assert check(ro, rh)
# TODO: fix for np.ulonglong, np.longlong and uint64
示例8: test_augmented_pow
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def test_augmented_pow(dtype, shape):
def fkt(a, c):
c[:] **= a
hfkt = hope.jit(fkt)
(ao, ah), (co, ch) = random(np.uint8, shape), random(dtype, shape)
if np.count_nonzero(ao == 0) > 0: ao[ao == 0] += 1
if np.count_nonzero(ah == 0) > 0: ah[ah == 0] += 1
if np.count_nonzero(co == 0) > 0: co[co == 0] += 1
if np.count_nonzero(ch == 0) > 0: ch[ch == 0] += 1
co, ch = np.copysign(np.sqrt(np.abs(co)), co).astype(dtype), np.copysign(np.sqrt(np.abs(ch)), ch).astype(dtype)
ao, ah = np.power(np.abs(ao).astype(np.float64), 1. / co.astype(np.float64)).astype(dtype), np.power(np.abs(ah).astype(np.float64), 1. / ch.astype(np.float64)).astype(dtype)
fkt(ao, co), hfkt(ah, ch)
assert check(co, ch)
# TODO: fix for np.ulonglong and uint64, std::power produce different results
示例9: get_item
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import ulonglong [as 别名]
def get_item(x, slices):
"""Extract elements from array with specified shape, axes and offsets.
Args:
x (:class:`~chainer.Variable` or :ref:`ndarray`):
A variable to be sliced.
slices (int, slice, Ellipsis, None, integer array-like, boolean\
array-like or tuple of them):
An object to specify the selection of elements.
Returns:
A :class:`~chainer.Variable` object which contains sliced array of
``x``.
.. note::
It only supports types that are supported by CUDA's atomicAdd when
an integer array is included in ``slices``.
The supported types are ``numpy.float32``, ``numpy.int32``,
``numpy.uint32``, ``numpy.uint64`` and ``numpy.ulonglong``.
.. note::
It does not support ``slices`` that contains multiple boolean arrays.
.. note::
See NumPy documentation for details of `indexing
<https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>`_.
.. admonition:: Example
>>> x = np.arange(12).reshape((2, 2, 3))
>>> x
array([[[ 0, 1, 2],
[ 3, 4, 5]],
<BLANKLINE>
[[ 6, 7, 8],
[ 9, 10, 11]]])
>>> F.get_item(x, 0)
variable([[0, 1, 2],
[3, 4, 5]])
>>> F.get_item(x, (0, 0, slice(0, 2, 1))) # equals x[0, 0, 0:2:1]
variable([0, 1])
>>> F.get_item(x, (Ellipsis, 2)) # equals x[..., 2]
variable([[ 2, 5],
[ 8, 11]])
>>> F.get_item(x, (1, np.newaxis, 1, 0)) # equals x[1, None, 1, 0]
variable([9])
"""
return GetItem(slices).apply((x,))[0]