numpy.errstate

class numpy.errstate(**kwargs)

with errstate(**state): –> operations in following block use given state.

# Set error handling to known state. >>> _ = np.seterr(invalid=’raise’, divide=’raise’, over=’raise’, ... under=’ignore’)

>>> a = -np.arange(3)
>>> with np.errstate(invalid='ignore'): # doctest: +SKIP
...     print np.sqrt(a)                # with statement requires Python 2.5
[ 0.     -1.#IND -1.#IND]
>>> print np.sqrt(a.astype(complex))
[ 0.+0.j          0.+1.j          0.+1.41421356j]
>>> print np.sqrt(a)
Traceback (most recent call last):
 ...
FloatingPointError: invalid value encountered in sqrt
>>> with np.errstate(divide='ignore'):  # doctest: +SKIP
...     print a/0
[0 0 0]
>>> print a/0
Traceback (most recent call last):
    ...
FloatingPointError: divide by zero encountered in divide

Previous topic

numpy.geterrcall

Next topic

numpy.seterrobj

This Page

Quick search