[Numpy-discussion] Context manager for seterr

Stefan van der Walt stefan at sun.ac.za
Sun Dec 14 19:40:07 EST 2014


On 2014-12-15 02:23:18, Julian Taylor <jtaylor.debian at googlemail.com> wrote:
> already exists as np.errstate:
>
> with np.errstate(divide='ignore'):

With 'ignore' a warning is still raised--is this by choice?

>>> import numpy as np
>>> x = np.array([0, 1, 2.])
>>> with np.errstate(divide='ignore'):
...     x/x
... 
__main__:2: RuntimeWarning: invalid value encountered in true_divide
array([ nan,   1.,   1.])


(I see it is documented that way as well, so I suspect so.)

Stéfan



More information about the NumPy-Discussion mailing list