[SciPy-User] confusion around return value from numpy.max

Keith Goodman kwgoodman at gmail.com
Sun May 1 14:43:32 EDT 2011


On Sun, May 1, 2011 at 11:34 AM, Martin van Leeuwen
<vanleeuwen.martin at gmail.com> wrote:
> HI All,
>
> I have a 2-dimensional array f that contains floating point values. I
> believe this array contains no NaNs.
>
> Is it possible to have nan returned by numpy.max() if an array
> contains no NaNs??
>
> To further illustrate my problem, I have the following two lines right
> after each other in my larger block of code:
>
>
> print numpy.sum(f==numpy.nan)
> print numpy.max(f)
>
>
> the first line prints 0 (zero), the second nan.

f == np.nan is alway False even if f contains NaNs (because a NaN is
not equal to a NaN). Try:

np.sum(np.isnan(f))



More information about the SciPy-User mailing list