本文整理汇总了Python中numpy.maximum_sctype方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.maximum_sctype方法的具体用法?Python numpy.maximum_sctype怎么用?Python numpy.maximum_sctype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.maximum_sctype方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_int_a2f
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def check_int_a2f(in_type, out_type):
# Check that array to / from file returns roughly the same as input
big_floater = np.maximum_sctype(np.float)
info = type_info(in_type)
this_min, this_max = info['min'], info['max']
if not in_type in np.sctypes['complex']:
data = np.array([this_min, this_max], in_type)
# Bug in numpy 1.6.2 on PPC leading to infs - abort
if not np.all(np.isfinite(data)):
if DEBUG:
print 'Hit PPC max -> inf bug; skip in_type %s' % in_type
return
else: # Funny behavior with complex256
data = np.zeros((2,), in_type)
data[0] = this_min + 0j
data[1] = this_max + 0j
str_io = BytesIO()
try:
scale, inter, mn, mx = calculate_scale(data, out_type, True)
except ValueError:
if DEBUG:
print in_type, out_type, sys.exc_info()[1]
return
array_to_file(data, str_io, out_type, 0, inter, scale, mn, mx)
data_back = array_from_file(data.shape, out_type, str_io)
data_back = apply_read_scaling(data_back, scale, inter)
assert_true(np.allclose(big_floater(data), big_floater(data_back)))
# Try with analyze-size scale and inter
scale32 = np.float32(scale)
inter32 = np.float32(inter)
if scale32 == np.inf or inter32 == np.inf:
return
data_back = array_from_file(data.shape, out_type, str_io)
data_back = apply_read_scaling(data_back, scale32, inter32)
# Clip at extremes to remove inf
info = type_info(in_type)
out_min, out_max = info['min'], info['max']
assert_true(np.allclose(big_floater(data),
big_floater(np.clip(data_back, out_min, out_max))))
示例2: test_int
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def test_int(self, t):
assert_equal(np.maximum_sctype(t), np.sctypes['int'][-1])
示例3: test_uint
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def test_uint(self, t):
assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1])
示例4: test_float
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def test_float(self, t):
assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1])
示例5: test_complex
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def test_complex(self, t):
assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1])
示例6: test_other
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def test_other(self, t):
assert_equal(np.maximum_sctype(t), t)
示例7: test_scale_min_max
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import maximum_sctype [as 别名]
def test_scale_min_max():
mx_dt = np.maximum_sctype(np.float)
for tp in np.sctypes['uint'] + np.sctypes['int']:
info = np.iinfo(tp)
# Need to pump up to max fp type to contain python longs
imin = np.array(info.min, dtype=mx_dt)
imax = np.array(info.max, dtype=mx_dt)
value_pairs = (
(0, imax),
(imin, 0),
(imin, imax),
(1, 10),
(-1, -1),
(1, 1),
(-10, -1),
(-100, 10))
for mn, mx in value_pairs:
# with intercept
scale, inter = scale_min_max(mn, mx, tp, True)
if mx-mn:
assert_array_almost_equal, (mx-inter) / scale, imax
assert_array_almost_equal, (mn-inter) / scale, imin
else:
assert_equal, (scale, inter), (1.0, mn)
# without intercept
if imin == 0 and mn < 0 and mx > 0:
(assert_raises, ValueError,
scale_min_max, mn, mx, tp, False)
continue
scale, inter = scale_min_max(mn, mx, tp, False)
assert_equal, inter, 0.0
if mn == 0 and mx == 0:
assert_equal, scale, 1.0
continue
sc_mn = mn / scale
sc_mx = mx / scale
assert_true, sc_mn >= imin
assert_true, sc_mx <= imax
if imin == 0:
if mx > 0: # numbers all +ve
assert_array_almost_equal, mx / scale, imax
else: # numbers all -ve
assert_array_almost_equal, mn / scale, imax
continue
if abs(mx) >= abs(mn):
assert_array_almost_equal, mx / scale, imax
else:
assert_array_almost_equal, mn / scale, imin