[Numpy-discussion] comparing arrays with NaN in them.

David Cournapeau cournape@gmail....
Fri Aug 24 11:04:38 CDT 2007


On 8/25/07, Matthieu Brucher <matthieu.brucher@gmail.com> wrote:
>
>
> 2007/8/24, mark <markbak@gmail.com>:
> > There may be multiple nan-s, but what Chris did is simply create one
> > with the same nan's
> >
> > >>> a = N.array((1,2,3,N.nan))
> > >>> b = N.array((1,2,3,N.nan))
> >
> > I think these should be the same.
> > Can anybody give me a good reason why they shouldn't, because it could
> > confuse a lot of people?
> >
> > Thanks, Mark
> >
>
> It's the IEEE norm for flotting point numbers. You can have sevaral
> different NaN, although in this case, they are the same kind.
> Even if they are the same kind, the norm tells that NaN != NaN.
>
AFAIK, this is the definition of Nan, eg on a system which FPU is IEEE
compatible, a number is x is NAN iff x != x. A Nan is defined at the
binary level as having the exponent to 1 everywhere, and any non zero
value in the mantissa:

 http://en.wikipedia.org/wiki/NaN

Personaly, I would simply compare the non Nan numbers if Nan is a
possible outcome of the operation. Checking at the binary level may
make sense, but it really depends on the cases.

David


More information about the Numpy-discussion mailing list