[Numpy-discussion] sorting -inf, nan, inf

A. M. Archibald peridot.faceted at gmail.com
Tue Sep 19 15:01:50 CDT 2006


On 19/09/06, Tim Hochberg <tim.hochberg at ieee.org> wrote:
> Keith Goodman wrote:
> > In what order would you like argsort to sort the values -inf, nan, inf?
> >
> Ideally, -inf should sort first, inf should sort last and nan should
> raise an exception if present.
>
> -tim

Mmm. Somebody who's working with NaNs has more or less already decided
they don't want to be pestered with exceptions for invalid data. I'd
be happy if they wound up at either end, but I'm not sure it's worth
hacking up the sort algorithm when a simple isnan() can pull them out.

What's happening now is that NaN<a, NaN==a, and NaN>a are all false,
which rather confuses the sorting algorithm. But as long as it doesn't
actually *break* (that is, leave some of the non-NaNs incorrectly
sorted) I don't care.

A. M. Archibald




More information about the Numpy-discussion mailing list