本文整理汇总了Python中numpy.geterr方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.geterr方法的具体用法?Python numpy.geterr怎么用?Python numpy.geterr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.geterr方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def setup(self):
# Base data definition.
x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
a10 = 10.
m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
xm = masked_array(x, mask=m1)
ym = masked_array(y, mask=m2)
z = np.array([-.5, 0., .5, .8])
zm = masked_array(z, mask=[0, 1, 0, 0])
xf = np.where(m1, 1e+20, x)
xm.set_fill_value(1e+20)
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
self.err_status = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
示例2: setUp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def setUp(self):
# Base data definition.
x = np.array([1., 1., 1., -2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
a10 = 10.
m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
xm = masked_array(x, mask=m1)
ym = masked_array(y, mask=m2)
z = np.array([-.5, 0., .5, .8])
zm = masked_array(z, mask=[0, 1, 0, 0])
xf = np.where(m1, 1e+20, x)
xm.set_fill_value(1e+20)
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
self.err_status = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
示例3: with_error_settings
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def with_error_settings(**new_settings):
"""
TODO.
Arguments:
**new_settings: TODO
Returns:
"""
@decorator.decorator
def dec(f, *args, **kwargs):
old_settings = np.geterr()
np.seterr(**new_settings)
ret = f(*args, **kwargs)
np.seterr(**old_settings)
return ret
return dec
示例4: test_basic_stats_generator_no_runtime_warnings_close_to_max_int
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def test_basic_stats_generator_no_runtime_warnings_close_to_max_int(self):
# input has batches with values that are slightly smaller than the maximum
# integer value.
less_than_max_int_value = np.iinfo(np.int64).max - 1
batches = ([
pa.RecordBatch.from_arrays([pa.array([[less_than_max_int_value]])],
['a'])
] * 2)
generator = basic_stats_generator.BasicStatsGenerator()
old_nperr = np.geterr()
np.seterr(over='raise')
accumulators = [
generator.add_input(generator.create_accumulator(), batch)
for batch in batches
]
generator.merge_accumulators(accumulators)
np.seterr(**old_nperr)
示例5: handleError
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def handleError(errorStatus, sourcemsg):
"""Take error status and use error mode to handle it."""
modes = np.geterr()
if errorStatus & np.FPE_INVALID:
if modes['invalid'] == "warn":
print("Warning: Encountered invalid numeric result(s)", sourcemsg)
if modes['invalid'] == "raise":
raise MathDomainError(sourcemsg)
if errorStatus & np.FPE_DIVIDEBYZERO:
if modes['dividebyzero'] == "warn":
print("Warning: Encountered divide by zero(s)", sourcemsg)
if modes['dividebyzero'] == "raise":
raise ZeroDivisionError(sourcemsg)
if errorStatus & np.FPE_OVERFLOW:
if modes['overflow'] == "warn":
print("Warning: Encountered overflow(s)", sourcemsg)
if modes['overflow'] == "raise":
raise NumOverflowError(sourcemsg)
if errorStatus & np.FPE_UNDERFLOW:
if modes['underflow'] == "warn":
print("Warning: Encountered underflow(s)", sourcemsg)
if modes['underflow'] == "raise":
raise UnderflowError(sourcemsg)
示例6: setUp
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def setUp (self):
"Base data definition."
x = np.array([1., 1., 1., -2., pi / 2.0, 4., 5., -10., 10., 1., 2., 3.])
y = np.array([5., 0., 3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])
a10 = 10.
m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]
m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1]
xm = masked_array(x, mask=m1)
ym = masked_array(y, mask=m2)
z = np.array([-.5, 0., .5, .8])
zm = masked_array(z, mask=[0, 1, 0, 0])
xf = np.where(m1, 1e+20, x)
xm.set_fill_value(1e+20)
self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf)
self.err_status = np.geterr()
np.seterr(divide='ignore', invalid='ignore')
示例7: _calc_triangle_angles
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def _calc_triangle_angles(p, eps=1e-5):
p1 = p[:, 0]
p2 = p[:, 1]
p3 = p[:, 2]
e1 = np.linalg.norm(p2 - p1, axis=1)
e2 = np.linalg.norm(p3 - p1, axis=1)
e3 = np.linalg.norm(p3 - p2, axis=1)
# Law Of Cossines
state = np.geterr()['invalid']
np.seterr(invalid='ignore')
a = np.zeros((p.shape[0], 3))
v = (e1 > eps) * (e2 > eps)
a[v, 0] = np.arccos((e2[v] ** 2 + e1[v] ** 2 - e3[v] ** 2) / (2 * e1[v] * e2[v]))
a[~v, 0] = 0
v = (e1 > eps) * (e3 > eps)
a[v, 1] = np.arccos((e1[v] ** 2 + e3[v] ** 2 - e2[v] ** 2) / (2 * e1[v] * e3[v]))
a[~v, 1] = 0
v = (e2 > eps) * (e3 > eps)
a[v, 2] = np.arccos((e2[v] ** 2 + e3[v] ** 2 - e1[v] ** 2) / (2 * e2[v] * e3[v]))
a[~v, 2] = 0
np.seterr(invalid=state)
a[np.isnan(a)] = np.pi
return a
示例8: test_default
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def test_default(self):
err = np.geterr()
assert_equal(err,
dict(divide='warn',
invalid='warn',
over='warn',
under='ignore')
)
示例9: test_numpy_err_state_is_default
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def test_numpy_err_state_is_default():
expected = {"over": "warn", "divide": "warn",
"invalid": "warn", "under": "ignore"}
import numpy as np
# The error state should be unchanged after that import.
assert np.geterr() == expected
示例10: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def __init__(self, casting='same_kind', err=None, dtype=None, sparse=None, **kw):
err = err if err is not None else np.geterr()
super().__init__(_casting=casting, _err=err, _dtype=dtype, _sparse=sparse, **kw)
示例11: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def __init__(self, decimals=None, casting='same_kind', err=None, dtype=None, sparse=False, **kw):
err = err if err is not None else np.geterr()
super().__init__(_decimals=decimals, _casting=casting, _err=err, _dtype=dtype,
_sparse=sparse, **kw)
示例12: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def __init__(self, deg=None, casting='same_kind', err=None, dtype=None, sparse=False, **kw):
err = err if err is not None else np.geterr()
super().__init__(_deg=deg, _casting=casting, _err=err, _dtype=dtype, _sparse=sparse, **kw)
示例13: test_default
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def test_default(self):
err = np.geterr()
self.assertEqual(err, dict(
divide='warn',
invalid='warn',
over='warn',
under='ignore',
))
示例14: test_set
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import geterr [as 别名]
def test_set(self):
with np.errstate():
err = np.seterr()
old = np.seterr(divide='print')
self.assertTrue(err == old)
new = np.seterr()
self.assertTrue(new['divide'] == 'print')
np.seterr(over='raise')
self.assertTrue(np.geterr()['over'] == 'raise')
self.assertTrue(new['divide'] == 'print')
np.seterr(**old)
self.assertTrue(np.geterr() == old)