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

Charles R Harris charlesr.harris at gmail.com
Tue Sep 19 14:52:01 CDT 2006


On 9/19/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


That sounds right. Nan can't be compared because, well, it is undefined. For
instance:

In [73]: a = arange(2)

In [74]: a/0
Out[74]: array([0, 0])

In [75]: a/0.0
Out[75]: array([              nan,               inf])

In [76]: a/(-0.0)
Out[76]: array([              nan,              -inf])

I.e., 0.0/0.0 is undefined. But unless the hardware generates the exception
I would be loath to introduce checks in the code. Putting a check in the
innermost loop of the sorts would cost significant time.

But look at the integer division by zero where the IEEE stuff has no
relevence. That sure looks like a bug to me.
<snip>

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20060919/2e1ec0b4/attachment-0001.html 


More information about the Numpy-discussion mailing list