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

2007-08-24 Thread Pierre GM
All, Using the maskedarray package: >>>import maskedarray as ma >>>x = numpy.array([1,numpy.nan,3]) >>>y = numpy.array([1,numpy.nan,3]) >>>ma.allclose(ma.array(x,mask=numpy.isnan(x)),ma.array(y,mask=numpy.isnan(y)) ) True or even simpler: >>> maskedarray.testutils.assert_equal(x,y) #

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

2007-08-24 Thread Christopher Barker
Timothy Hochberg wrote: > in principle it's not safe to rely on NaNs being bitwise equal. Thanks Tim, I always learn a lot on this list. Anyway, I think my suggestion of "binary equal" wasn't really what I want. What I want is essentially a NaN-safe comparison, much like the NaN-safe functions

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

2007-08-24 Thread Timothy Hochberg
On 8/24/07, Timothy Hochberg <[EMAIL PROTECTED]> wrote: > > > > On 8/24/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > [SNIP] > > > > You can have several different NaN, > > > > You can? I thought NaN was defined by IEEE 754 as a particular bit > > pattern (one for each precision, anyway). >

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

2007-08-24 Thread David Goldsmith
Never mind. (Posted that before finishing the thread, sorry). DG David Goldsmith wrote: > What is meant by "multiple nan-s"? > > DG > > mark wrote: > >> 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)

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

2007-08-24 Thread David Goldsmith
What is meant by "multiple nan-s"? DG mark wrote: > 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 re

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

2007-08-24 Thread Timothy Hochberg
On 8/24/07, Christopher Barker <[EMAIL PROTECTED]> wrote: [SNIP] > You can have several different NaN, > > You can? I thought NaN was defined by IEEE 754 as a particular bit > pattern (one for each precision, anyway). There's more than one way to spell NaN in binary and they tend to mean diffe

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

2007-08-24 Thread Christopher Barker
Matthieu Brucher wrote: > 2007/8/24, mark <[EMAIL PROTECTED] >: > 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

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

2007-08-24 Thread David Cournapeau
On 8/25/07, Matthieu Brucher <[EMAIL PROTECTED]> wrote: > > > 2007/8/24, mark <[EMAIL PROTECTED]>: > > 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

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

2007-08-24 Thread Glen W. Mabey
On Fri, Aug 24, 2007 at 05:25:43PM +0200, Matthieu Brucher wrote: > 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. Someone mentioned using masked a

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

2007-08-24 Thread Matthieu Brucher
2007/8/24, mark <[EMAIL PROTECTED]>: > > 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, becau

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

2007-08-24 Thread mark
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 p

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

2007-08-23 Thread Warren Focke
On Thu, 23 Aug 2007, Christopher Barker wrote: > but that feels like a kludge. maybe some sort of "TheseArrays are binary > equal" would be useful. But there are multiple possible NaNs, so you couldn't rely on the bits comparing. Maybe something with masked arrays? w ___

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

2007-08-23 Thread Christopher Barker
Hi all, I was just trying to write a unit test for something where I was expecting to get some NaN's in the array. However, since NaN == NaN returns false, the simple test: assert(alltrue(a == b)) >>> a = N.array((1,2,3,N.nan)) >>> b = N.array((1,2,3,N.nan)) >>> a == b array([ True, True,