[Numpy-discussion] Runtime Warning by numpy.divide(0.0, 0.0) can't be ignored
Robert Kern
robert.kern at gmail.com
Mon Sep 23 06:28:09 EDT 2013
On Monday, September 23, 2013, Lorenzo Di Gregorio wrote:
> Hello,
>
> numpy.divide(0.0,0.0) raises a warning which doesn't appear to get caught
> by numpy.seterr(divide='ignore')
>
> This example:
>
> import numpy
> numpy.divide(0.0,0.0)
> numpy.divide(1.0,0.0)
> numpy.seterr(divide='ignore')
> numpy.divide(1.0,0.0)
> numpy.divide(0.0,0.0)
>
> produces this output:
>
> Warning (from warnings module):
> File "C:\Users\ldigrego\Desktop\tst.py", line 2
> numpy.divide(0.0,0.0)
> RuntimeWarning: invalid value encountered in divide
>
> Warning (from warnings module):
> File "C:\Users\ldigrego\Desktop\tst.py", line 3
> numpy.divide(1.0,0.0)
> RuntimeWarning: divide by zero encountered in divide
>
> Warning (from warnings module):
> File "C:\Users\ldigrego\Desktop\tst.py", line 6
> numpy.divide(0.0,0.0)
> RuntimeWarning: invalid value encountered in divide
>
> Strangely, on Ipython the numpy.seterr(divide='ignore') seems to catch the
> warning:
>
> import numpy
> numpy.divide(0.0,0.0)
> Out[1]: nan
> C:\eclipse\plugins\org.python.pydev_2.8.1.2013072611\pysrc\pydevconsole.py:1:
> RuntimeWarning: invalid value encountered in divide
> from __future__ import nested_scopes #Jython 2.1 support
> numpy.divide(1.0,0.0)
> Out[1]: inf
> C:\eclipse\plugins\org.python.pydev_2.8.1.2013072611\pysrc\pydevconsole.py:1:
> RuntimeWarning: divide by zero encountered in divide
> from __future__ import nested_scopes #Jython 2.1 support
> numpy.seterr(divide='ignore')
> Out[1]: {'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under':
> 'ignore'}
> numpy.divide(1.0,0.0)
> Out[1]: inf
> numpy.divide(0.0,0.0)
> Out[1]: nan
>
> I could not find information on Google: is this a known problem? Is there
> a way to suppress this warning
>
This is not a division warning. It is warning you that a NaN (an "invalid
value") was generated. It can be controlled using "invalid='ignore'". The
reason that it looks like you suppressed it in the IPython example is that
you triggered the warning earlier. The behavior of warnings is that they
only get issued once for each code location. So the second time you
attempted it after setting "divide='ignore'" it wasn't going to show up
anyways.
> I'm working on a 64b Win7 machine employing
> numpy-MKL-1.7.0.win-amd64-py2.7.exe.
>
> Best Regards,
> Lorenzo
>
--
Robert Kern
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130923/3d096807/attachment.html>
More information about the NumPy-Discussion
mailing list