本文整理汇总了Python中numpy.uintc方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.uintc方法的具体用法?Python numpy.uintc怎么用?Python numpy.uintc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.uintc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _unsigned_subtract
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uintc [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 uintc [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: test_numpy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uintc [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)
示例4: test_vector_buffer_numpy
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uintc [as 别名]
def test_vector_buffer_numpy():
a = np.array([1, 2, 3, 4], dtype=np.int32)
with pytest.raises(TypeError):
m.VectorInt(a)
a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=np.uintc)
v = m.VectorInt(a[0, :])
assert len(v) == 4
assert v[2] == 3
ma = np.asarray(v)
ma[2] = 5
assert v[2] == 5
v = m.VectorInt(a[:, 1])
assert len(v) == 3
assert v[2] == 10
v = m.get_vectorstruct()
assert v[0].x == 5
ma = np.asarray(v)
ma[1]['x'] = 99
assert v[1].x == 99
v = m.VectorStruct(np.zeros(3, dtype=np.dtype([('w', 'bool'), ('x', 'I'),
('y', 'float64'), ('z', 'bool')], align=True)))
assert len(v) == 3
示例5: native
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import uintc [as 别名]
def native(data,
format = segyio.SegySampleFormat.IBM_FLOAT_4_BYTE,
copy = True):
"""Convert numpy array to native float
Converts a numpy array from raw segy trace data to native floats. Works for numpy ndarrays.
Parameters
----------
data : numpy.ndarray
format : int or segyio.SegySampleFormat
copy : bool
If True, convert on a copy, and leave the input array unmodified
Returns
-------
data : numpy.ndarray
Notes
-----
.. versionadded:: 1.1
Examples
--------
Convert mmap'd trace to native float:
>>> d = np.memmap('file.sgy', offset = 3600, dtype = np.uintc)
>>> samples = 1500
>>> trace = segyio.tools.native(d[240:240+samples])
"""
data = data.view( dtype = np.single )
if copy:
data = np.copy( data )
format = int(segyio.SegySampleFormat(format))
return segyio._segyio.native(data, format)