[Numpy-discussion] Medians that ignore values

Pierre GM pgmdevlist@gmail....
Fri Sep 19 03:32:23 CDT 2008

On Friday 19 September 2008 04:10:24 Anne Archibald wrote:

> (is there a convenience
> function that makes a masked array with a mask everywhere the data is
> nan?).

numpy.ma.fix_invalid, that masks your Nans and Infs and sets the underlying 
data to some filling value. That way, you don't carry NaNs/Infs along.

> I am assuming that appropriate masked sort/amax/maximum/mean/median
> exist already. They're definitely needed, so how much effort is it
> worth putting in to duplicate that functionality with nans instead of
> masked elements?

My opinion indeed. The MaskedArray.sort method has an extra flag that lets you 
decide whether you want masked data at the beginning or the end of your 
That said, numpy.nanmin, numpy.nansum... don't come with the heavy machinery 
of numpy.ma, and are therefore faster. 
I'm really going to have to learn C.

More information about the Numpy-discussion mailing list