[Numpy-discussion] Medians that ignore values

Anne Archibald peridot.faceted@gmail....
Fri Sep 19 01:56:12 CDT 2008

2008/9/19 David Cournapeau <david@ar.media.kyoto-u.ac.jp>:
> Anne Archibald wrote:
>> That was in amax/amin. Pretty much every other function that does
>> comparisons needs to be fixed to work with nans. In some cases it's
>> not even clear how: where should a sort put the nans in an array?
> The problem is more on how the functions use sort than sort itself in
> the case of median. There can't be a 'good' way to put nan in soft, for
> example, since nans cannot be ordered.

Well, for example, you might ask that all the non-nan elements be in
order, even if you don't specify where the nan goes.

> I don't know about the best strategy: either we fix every function using
> comparison, handling nan as a special case as you mentioned, or there
> may be a more clever thing to do to avoid special casing everywhere. I
> don't have a clear idea of how many functions rely on ordering in numpy.

You can always just set numpy to raise an exception whenever it comes
across a nan. In fact, apart from the difficulty of correctly frobbing
numpy's floating-point handling, how reasonable is it for (say) median
to just run as it is now, but if an exception is thrown, fall back to
a nan-aware version?


More information about the Numpy-discussion mailing list