RuntimeWarning: divide by zero encountered in log
Is there a way to get a traceback instead of just printing the line that triggered the error?
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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion Neal,
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 RuntimeWarning. Example $ cat foo.py import numpy as np np.seterr(divide='raise') 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 Cheers, - Jonathan Helmus
On 16 May 2013 19:48, "Jonathan Helmus" <jjhelmus@gmail.com> wrote:
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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion Neal,
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 RuntimeWarning.
Example
$ cat foo.py import numpy as np
np.seterr(divide='raise')
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
You also have the option of using Python's general ability to customize how any warning is handled - see the 'warnings' module and -W switch. If you just want a traceback printed without an exception then I think you can do that with np.seterr too (using np.seterrcall). -n
Nathaniel Smith wrote:
On 16 May 2013 19:48, "Jonathan Helmus" <jjhelmus@gmail.com> wrote:
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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion Neal,
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 RuntimeWarning.
Example
$ cat foo.py import numpy as np
np.seterr(divide='raise')
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
You also have the option of using Python's general ability to customize how any warning is handled - see the 'warnings' module and -W switch.
If you just want a traceback printed without an exception then I think you can do that with np.seterr too (using np.seterrcall).
-n
I tried this: import traceback np.seterrcall (lambda a,b: traceback.print_stack) np.seterr (all='call') np.seterrcall (lambda a,b: traceback.print_stack) but it doesn't seem to do anything, I still see numpy warning as before.
Neal Becker wrote:
Nathaniel Smith wrote:
On 16 May 2013 19:48, "Jonathan Helmus" <jjhelmus@gmail.com> wrote:
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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion Neal,
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 RuntimeWarning.
Example
$ cat foo.py import numpy as np
np.seterr(divide='raise')
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
You also have the option of using Python's general ability to customize how any warning is handled - see the 'warnings' module and -W switch.
If you just want a traceback printed without an exception then I think you can do that with np.seterr too (using np.seterrcall).
-n
I tried this:
import traceback
np.seterrcall (lambda a,b: traceback.print_stack) np.seterr (all='call') np.seterrcall (lambda a,b: traceback.print_stack)
but it doesn't seem to do anything, I still see numpy warning as before.
Here's a trivial test: import numpy as np import traceback np.seterrcall (lambda a,b: traceback.print_stack) np.seterr (all='call') np.seterrcall (lambda a,b: traceback.print_stack) print 1./0
On 17 May 2013 14:17, "Neal Becker" <ndbecker2@gmail.com> wrote:
Nathaniel Smith wrote:
On 16 May 2013 19:48, "Jonathan Helmus" <jjhelmus@gmail.com> wrote:
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@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion Neal,
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 RuntimeWarning.
Example
$ cat foo.py import numpy as np
np.seterr(divide='raise')
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
You also have the option of using Python's general ability to customize
how
any warning is handled - see the 'warnings' module and -W switch.
If you just want a traceback printed without an exception then I think you can do that with np.seterr too (using np.seterrcall).
-n
I tried this:
import traceback
np.seterrcall (lambda a,b: traceback.print_stack) np.seterr (all='call')
Try adding some parens? np.seterrcall (lambda a,b: traceback.print_stack()) -n
participants (3)
-
Jonathan Helmus
-
Nathaniel Smith
-
Neal Becker