[Numpy-discussion] numpy log and exceptions

Daniel Hyams dhyams at gmail.com
Tue Oct 21 23:52:33 EDT 2014

I would have thought that this snippet would raise an exception:

import numpy
a = numpy.array([1.0,0.0,-1.0])
b = numpy.log(a)

I get as a result (in b): [0, -Inf, NaN]

It's basically the same issue as:


Except that I have explicitly set the error flags to raise exceptions.  It 
works fine for sqrt(), but not for log().  I've checked numpy 1.4.0 and 
1.7.1 and both have the same behavior.

Is there a way to force the log (and log10) function to raise an exception 
on invalid input?

More information about the NumPy-Discussion mailing list