[Numpy-discussion] min() of array containing NaN
Thomas J. Duck
Tue Aug 12 10:02:47 CDT 2008
Christopher Barker wrote:
> well, it's not a bug because the result if there is a NaN is
> 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.
This is exactly what happened to me. I was getting crazy
results when contour plotting with matplotlib, although the pcolor
plots looked fine. In particular, the colorscale had incorrect
limits. This led me to check the min() and max() values in my array,
which were clearly wrong as illustrated by the pcolor plot. Further
investigation revealed unexpected NaNs in my array.
> 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
> does slow things down too much, there could be a flag that lets you
> it off.
It is quite often the case that NaNs are unexpected, so it
would be helpful to raise an Exception.
Thanks for all of the helpful discussion on this issue.
Thomas J. Duck <firstname.lastname@example.org>
Department of Physics and Atmospheric Science, Dalhousie University,
Halifax, Nova Scotia, Canada, B3H 3J5.
Tel: (902)494-1456 | Fax: (902)494-5191 | Lab: (902)494-3813
More information about the Numpy-discussion