本文整理汇总了Python中numpy.half方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.half方法的具体用法?Python numpy.half怎么用?Python numpy.half使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.half方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_floating_overflow
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def test_floating_overflow(self):
""" Strings containing an unrepresentable float overflow """
fhalf = np.half('1e10000')
assert_equal(fhalf, np.inf)
fsingle = np.single('1e10000')
assert_equal(fsingle, np.inf)
fdouble = np.double('1e10000')
assert_equal(fdouble, np.inf)
flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000')
assert_equal(flongdouble, np.inf)
fhalf = np.half('-1e10000')
assert_equal(fhalf, -np.inf)
fsingle = np.single('-1e10000')
assert_equal(fsingle, -np.inf)
fdouble = np.double('-1e10000')
assert_equal(fdouble, -np.inf)
flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000')
assert_equal(flongdouble, -np.inf)
示例2: _asfarray
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def _asfarray(x):
"""Like numpy asfarray, except that it does not modify x dtype if x is
already an array with a float dtype, and do not cast complex types to
real."""
if hasattr(x, "dtype") and x.dtype.char in numpy.typecodes["AllFloat"]:
# 'dtype' attribute does not ensure that the
# object is an ndarray (e.g. Series class
# from the pandas library)
if x.dtype == numpy.half:
# no half-precision routines, so convert to single precision
return numpy.asarray(x, dtype=numpy.float32)
return numpy.asarray(x, dtype=x.dtype)
else:
# We cannot use asfarray directly because it converts sequences of
# complex to sequence of real
ret = numpy.asarray(x)
if ret.dtype == numpy.half:
return numpy.asarray(ret, dtype=numpy.float32)
elif ret.dtype.char not in numpy.typecodes["AllFloat"]:
return numpy.asfarray(x)
return ret
示例3: test_roundtrip_half
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def test_roundtrip_half(self):
half_list = [
1.0,
-2.0,
6.5504 * 10**4, # (max half precision)
2**-14, # ~= 6.10352 * 10**-5 (minimum positive normal)
2**-24, # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal)
0.0,
-0.0,
float('+inf'),
float('-inf'),
0.333251953125, # ~= 1/3
]
x = np.array(half_list, dtype='>e')
self._check_roundtrip(x)
x = np.array(half_list, dtype='<e')
self._check_roundtrip(x)
示例4: test_singleton
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def test_singleton(self):
ftype = finfo(half)
ftype2 = finfo(half)
assert_equal(id(ftype), id(ftype2))
示例5: test_precision
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def test_precision(self):
# not looping results in a useful stack trace upon failure
self.do_precision(np.half, np.single)
self.do_precision(np.half, np.double)
self.do_precision(np.half, np.longdouble)
self.do_precision(np.single, np.double)
self.do_precision(np.single, np.longdouble)
self.do_precision(np.double, np.longdouble)
示例6: _generate_latlon_arrays
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def _generate_latlon_arrays(array, transformer, geotransform):
def generate_latlon_for_here(x, y):
return generate_latlon(x, y, geotransform, transformer)
# The crude way. Ask someone if it is doable.
top_lat, left_lon = generate_latlon_for_here(0,0)
bottom_lat, right_lon = generate_latlon_for_here(array.shape[0]-1, array.shape[1]-1)
lat_list = np.linspace(top_lat, bottom_lat, array.shape[1], dtype=np.half)
lon_list = np.linspace(left_lon, right_lon, array.shape[0], dtype=np.half)
lat_array = np.stack([lat_list]*array.shape[0])
lon_array = np.stack([lon_list]*array.shape[1]).T
return lat_array, lon_array
示例7: calc_azimuth_array
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def calc_azimuth_array(lat_array, lon_array, raster_datetime):
def calc_azimuth_for_datetime(lat, lon):
return solar.get_azimuth_fast(lat, lon, raster_datetime).astype(np.dtype(np.half))
return np.array(list(map(calc_azimuth_for_datetime, lat_array, lon_array)))
示例8: test_export_record
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import half [as 别名]
def test_export_record(self):
dt = [('a', 'b'),
('b', 'h'),
('c', 'i'),
('d', 'l'),
('dx', 'q'),
('e', 'B'),
('f', 'H'),
('g', 'I'),
('h', 'L'),
('hx', 'Q'),
('i', np.single),
('j', np.double),
('k', np.longdouble),
('ix', np.csingle),
('jx', np.cdouble),
('kx', np.clongdouble),
('l', 'S4'),
('m', 'U4'),
('n', 'V3'),
('o', '?'),
('p', np.half),
]
x = np.array(
[(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
asbytes('aaaa'), 'bbbb', asbytes(' '), True, 1.0)],
dtype=dt)
y = memoryview(x)
assert_equal(y.shape, (1,))
assert_equal(y.ndim, 1)
assert_equal(y.suboffsets, EMPTY)
sz = sum([dtype(b).itemsize for a, b in dt])
if dtype('l').itemsize == 4:
assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
else:
assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}')
# Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides
if not (np.ones(1).strides[0] == np.iinfo(np.intp).max):
assert_equal(y.strides, (sz,))
assert_equal(y.itemsize, sz)