[Numpy-discussion] min() of array containing NaN
Andrew Dalke
dalke at dalkescientific.com
Tue Aug 12 01:46:58 EDT 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 at dalkescientific.com
More information about the NumPy-Discussion
mailing list