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

Andrew Dalke dalke@dalkescientific....
Tue Aug 12 00:46:58 CDT 2008


On Aug 12, 2008, at 7:05 AM, Christopher Barker wrote:
> 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.


Here's the implementation, from lib/function_base.py

def nanmin(a, axis=None):
     """Find the minimium over the given axis, ignoring NaNs.
     """
     y = array(a,subok=True)
     if not issubclass(y.dtype.type, _nx.integer):
         y[isnan(a)] = _nx.inf
     return y.min(axis)

This is buggy for the case of a list containing only NaNs.

 >>> import numpy as np
 >>> np.NAN
nan
 >>> np.min([np.NAN])
nan
 >>> np.nanmin([np.NAN])
inf
 >>>


				Andrew
				dalke@dalkescientific.com




More information about the Numpy-discussion mailing list