numpy.seterr(all=None, divide=None, over=None, under=None, invalid=None)
[source]
Set how floating-point errors are handled.
Note that operations on integer scalar types (such as int16
) are handled like floating point, and are affected by these settings.
Parameters: |
|
---|---|
Returns: |
|
The floating-point exceptions are defined in the IEEE 754 standard [1]:
[1] | https://en.wikipedia.org/wiki/IEEE_754 |
>>> old_settings = np.seterr(all='ignore') #seterr to known value >>> np.seterr(over='raise') {'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'} >>> np.seterr(**old_settings) # reset to default {'divide': 'ignore', 'over': 'raise', 'under': 'ignore', 'invalid': '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
>>> from collections import OrderedDict >>> old_settings = np.seterr(all='print') >>> OrderedDict(np.geterr()) OrderedDict([('divide', 'print'), ('over', 'print'), ('under', 'print'), ('invalid', 'print')]) >>> np.int16(32000) * np.int16(3) 30464
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.17.0/reference/generated/numpy.seterr.html