Is there a better way of making numpy.argmin() ignore NaN values Is there a better way of making numpy.argmin() ignore NaN values arrays arrays

Is there a better way of making numpy.argmin() ignore NaN values


Sure! Use nanargmin:

import numpy as npa = np.array([ np.nan,   2.5,   3.,  np.nan,   4.,   5.])print(np.nanargmin(a))# 1

There is also nansum, nanmax, nanargmax, and nanmin,

In scipy.stats, there is nanmean and nanmedian.

For more ways to ignore nans, check out masked arrays.