[Numpy-discussion] Difference between shape=() and shape=(1,)

Friedrich Romstedt friedrichromstedt@gmail....
Sat Jul 17 11:47:51 CDT 2010


2010/7/13 John Reid <j.reid@mail.cryst.bbk.ac.uk>:
> Hi,
>
> I have some arrays of various shapes in which I need to set any NaNs to
> 0.

I just ran across numpy.nan_to_num():

>>> a = numpy.log(-1)
>>> b = numpy.log([-1, 1])
>>> a
nan
>>> b
array([ NaN,   0.])
>>> numpy.nan_to_num(a)
0.0
>>> numpy.nan_to_num(b)
array([ 0.,  0.])

Friedrich


More information about the NumPy-Discussion mailing list