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

A. M. Archibald peridot.faceted at gmail.com
Tue Sep 19 20:41:30 EDT 2006


On 19/09/06, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
>
>
> For floats we could use something like:
>
> lessthan(a,b) := a < b || (a == nan && b != nan)
>
> Which would put all the nans at one end and might not add too much overhead.

You could put an any(isnan()) out front and run this slower version
only if there are any NaNs (also, you can't use == for NaNs, you have
to use C isNaN). But I'm starting to see the wisdom in simply throwing
an exception, since sorting is not well-defined with NaNs.

A. M. Archibald




More information about the NumPy-Discussion mailing list