[Numpy-discussion] Medians that ignore values

Peter Saffrey pzs at dcs.gla.ac.uk
Fri Sep 19 12:02:08 EDT 2008


Alan G Isaac <aisaac <at> american.edu> writes:

> Recently I needed to fill a 2d array with values
> from computations that could "go wrong".
> I created an array of NaN and then replaced
> the elements where the computation produced
> a useful value.  I then applied ``nanmax``,
> to get the maximum of the useful values.
> 

I'm glad you posted this, because this is exactly the method I'm using. How do
you detect whether there are still any missing spots in your array? nan has some
rather unfortunate properties:

>>> from numpy import *
>>> a = array([1,2,nan])
>>> nan in a
False
>>> nan == nan
False

Should I take the earlier advice and switch to masked arrays?

Peter




More information about the NumPy-Discussion mailing list