numpy.geterr#

numpy.geterr()[source]#

Get the current way of handling floating-point errors.

Returns:
resdict

A dictionary with keys β€œdivide”, β€œover”, β€œunder”, and β€œinvalid”, whose values are from the strings β€œignore”, β€œprint”, β€œlog”, β€œwarn”, β€œraise”, and β€œcall”. The keys represent possible floating-point exceptions, and the values define how these exceptions are handled.

Notes

For complete documentation of the types of floating-point exceptions and treatment options, see seterr.

Examples

>>> import numpy as np
>>> np.geterr()
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
>>> np.arange(3.) / np.arange(3.)  
array([nan,  1.,  1.])
RuntimeWarning: invalid value encountered in divide
>>> oldsettings = np.seterr(all='warn', invalid='raise')
>>> np.geterr()
{'divide': 'warn', 'over': 'warn', 'under': 'warn', 'invalid': 'raise'}
>>> np.arange(3.) / np.arange(3.)
Traceback (most recent call last):
  ...
FloatingPointError: invalid value encountered in divide
>>> oldsettings = np.seterr(**oldsettings)  # restore original