原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.seterr.html
校对:(虚位以待)
numpy.
seterr
(all=None, divide=None, over=None, under=None, invalid=None)[source]设置如何处理浮点错误。
请注意,对整数标量类型(例如int16
)的操作将像浮点一样处理,并受这些设置的影响。
参数: | all:{'ignore','warn','raise','call','print','log'}
divide:{'ignore','warn','raise','call','print','log'}
over:{'ignore','warn','raise','call','print','log'}
在下:{'ignore','warn','raise','call','print','log'}
无效:{'ignore','warn','raise','call','print','log'}
|
---|---|
返回: | old_settings:dict
|
笔记
浮点异常在IEEE 754标准[1]中定义:
[R281] | http://en.wikipedia.org/wiki/IEEE_754 |
例子
>>> old_settings = np.seterr(all='ignore') #seterr to known value
>>> np.seterr(over='raise')
{'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore',
'under': 'ignore'}
>>> np.seterr(**old_settings) # reset to default
{'over': 'raise', 'divide': 'ignore', 'invalid': 'ignore', 'under': 'ignore'}
>>> np.int16(32000) * np.int16(3)
30464
>>> old_settings = np.seterr(all='warn', over='raise')
>>> np.int16(32000) * np.int16(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FloatingPointError: overflow encountered in short_scalars
>>> old_settings = np.seterr(all='print')
>>> np.geterr()
{'over': 'print', 'divide': 'print', 'invalid': 'print', 'under': 'print'}
>>> np.int16(32000) * np.int16(3)
Warning: overflow encountered in short_scalars
30464