<br><br>On Monday, September 23, 2013, Lorenzo Di Gregorio wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello,<div><br></div><div>numpy.divide(0.0,0.0) raises a warning which doesn't appear to get caught by numpy.seterr(divide='ignore')</div>
<div><br></div><div>This example:</div><div><br></div><div>
<div>import numpy</div><div>numpy.divide(0.0,0.0)</div><div>numpy.divide(1.0,0.0)</div><div>numpy.seterr(divide='ignore')</div><div>numpy.divide(1.0,0.0)</div><div>numpy.divide(0.0,0.0)</div><div><br></div><div>produces this output:</div>
<div><br></div><div><div>Warning (from warnings module):</div><div> File "C:\Users\ldigrego\Desktop\tst.py", line 2</div><div> numpy.divide(0.0,0.0)</div><div>RuntimeWarning: invalid value encountered in divide</div>
<div><br></div><div>Warning (from warnings module):</div><div> File "C:\Users\ldigrego\Desktop\tst.py", line 3</div><div> numpy.divide(1.0,0.0)</div><div>RuntimeWarning: divide by zero encountered in divide</div>
<div><br></div><div>Warning (from warnings module):</div><div> File "C:\Users\ldigrego\Desktop\tst.py", line 6</div><div> numpy.divide(0.0,0.0)</div><div>RuntimeWarning: invalid value encountered in divide</div>
</div><div><br></div><div>Strangely, on Ipython the numpy.seterr(divide='ignore') seems to catch the warning:</div><div><br></div><div><div>import numpy</div><div>numpy.divide(0.0,0.0)</div><div>Out[1]: nan</div>
<div>
C:\eclipse\plugins\org.python.pydev_2.8.1.2013072611\pysrc\pydevconsole.py:1: RuntimeWarning: invalid value encountered in divide</div><div> from __future__ import nested_scopes #Jython 2.1 support</div><div>numpy.divide(1.0,0.0)</div>
<div>Out[1]: inf</div><div>C:\eclipse\plugins\org.python.pydev_2.8.1.2013072611\pysrc\pydevconsole.py:1: RuntimeWarning: divide by zero encountered in divide</div><div> from __future__ import nested_scopes #Jython 2.1 support</div>
<div>numpy.seterr(divide='ignore')</div><div>Out[1]: {'divide': 'warn', 'invalid': 'warn', 'over': 'warn', 'under': 'ignore'}</div><div>numpy.divide(1.0,0.0)</div>
<div>Out[1]: inf</div><div>numpy.divide(0.0,0.0)</div><div>Out[1]: nan</div></div><div><br></div><div>I could not find information on Google: is this a known problem? Is there a way to suppress this warning</div></div></div>
</blockquote><div><br></div><div>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.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>I'm working on a 64b Win7 machine employing numpy-MKL-1.7.0.win-amd64-py2.7.exe.</div>
</div><div><br></div><div>Best Regards,</div><div>Lorenzo</div></div>
</blockquote><br><br>-- <br>Robert Kern<br>