[Numpy-discussion] min() of array containing NaN

Christopher Barker Chris.Barker at noaa.gov
Tue Aug 12 01:05:26 EDT 2008


Bruce Southey wrote:
> Actually this could be viewed as a bug because it ignores the entries
> to the left of the NaN.

well, it's not a bug because the result if there is a NaN is undefined. 
However, it sure could trip people up. If you know there is likely to be 
a NaN in there, then you could use nanmin() or masked arrays. The 
problem comes up when you have no idea there might be a NaN in there, in 
which case you get a bogus answer -- this is very bad.

Is there an error state that will trigger an error or warning in these 
situations? Otherwise, I'd have to say that the default should be to 
test for NaN's, and either raise an error or return NaN. If that really 
does slow things down too much, there could be a flag that lets you turn 
it off.

This situation now makes me very nervous.

>  because
> nanmin treats NaNs as zero, positive infinity as a really large
> positive number and negative infinity as a very small or negative
> number.

Actually, I think it skips over NaN -- otherwise, the min would always 
be zero if there where a Nan, and "a very small negative number" if 
there were a -inf.

I have to say that one of the things I always liked about Matlab was 
it's handling of NaN, inf, and -inf.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT         (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception



More information about the NumPy-Discussion mailing list