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

Keith Goodman kwgoodman at gmail.com
Tue Jul 17 07:46:20 EDT 2007

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()

>> 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.

More information about the NumPy-Discussion mailing list