[Numpy-discussion] RuntimeWarning: divide by zero encountered in log

Jonathan Helmus jjhelmus at gmail.com
Thu May 16 14:47:56 EDT 2013

On 05/16/2013 01:42 PM, Neal Becker wrote:
> Is there a way to get a traceback instead of just printing the
> line that triggered the error?
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

     Look at the numpy.seterr function.  You can use it to change how 
floating-point errors are handled, including raising a 
FloatingPointError with a traceback as opposed to printing a 


$ cat foo.py
import numpy as np


a = np.array([1,1,1], dtype='float32')
a / 0

$ python foo.py
Traceback (most recent call last):
   File "test.py", line 6, in <module>
     a / 0
FloatingPointError: divide by zero encountered in divide


     - Jonathan Helmus

More information about the NumPy-Discussion mailing list