[Numpy-discussion] What is the different between nanmin and min ?
Tue Jul 17 11:01:27 CDT 2007
On 7/17/07, Keith Goodman <firstname.lastname@example.org> wrote:
> On 7/17/07, David Cournapeau <email@example.com> wrote:
> > I noticed that min and max already ignore Nan, which raises the
> > question: why are there nanmin and nanmax functions ?
> Using min and max when you have NaNs is dangerous. Here's an example:
> >> x = M.matrix([[ 1.0, 2.0, M.nan]])
> >> x.min()
> >> x = M.matrix([[ M.nan, 2.0, 1.0]])
> >> x.min()
> I wish that min and max ignored NaNs. For me taking the time to check
> for NaNs (slowing down min and max) is worth it. But it seems like
> most people disagree. So I use nanmin and nanmax instead.
The time is one issue. Another is that ignoring NaNs is only correct if you
are treating NaNs as missing values. If instead you are treating them as non
numbers, the results of some bogus computation, then raising an error is a
more appropriate response. If one was going to take the time to check for
NaNs, one strategy that I would probably support would be to ignore the
NaNs, but set the invalid flag. If the error state for invalid was set to
ignore, then this would work as the missing value camp likes, otherwise it
would raise an error or signal a warning.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion