[Numpy-discussion] What is the different between nanmin and min ?

Timothy Hochberg tim.hochberg at ieee.org
Tue Jul 17 12:01:27 EDT 2007


On 7/17/07, Keith Goodman <kwgoodman at gmail.com> wrote:
>
> On 7/17/07, David Cournapeau <david at ar.media.kyoto-u.ac.jp> 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()
> 1.0
>
> >> x = M.matrix([[ M.nan, 2.0, 1.0]])
> >> x.min()
> nan
>
> 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.



-- 
.  __
.   |-\
.
.  tim.hochberg at ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20070717/92ec0358/attachment.html>


More information about the NumPy-Discussion mailing list