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

Martin van Leeuwen vanleeuwen.martin at gmail.com
Sun May 1 14:52:13 EDT 2011


Hi Keith,

Thanks. I didn't know f == numpy.nan always return False, but it's
certainly good to know (and probably makes a lot of sense too).

numpy.isnan(f) works fine indeed.

Thanks again,

Martin



2011/5/1 Keith Goodman <kwgoodman at gmail.com>:
> 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))
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list