[Numpy-discussion] Comparing arrays with dtypes with field names
Albert Strasheim
fullung at gmail.com
Thu Jul 6 03:08:36 CDT 2006
Hello all
I noticed that arrays with dtypes with field names don't compare correctly
when using the equality operator.
Example:
In [17]: dt = N.dtype({'names' : ['f1', 'f2'],
'formats' : [N.intc, N.intc]})
In [18]: x = N.array([(0,0)], dtype=dt)
In [19]: y = N.array([(0,0)], dtype=dt)
In [20]: x['f1']==y['f1']
Out[20]: array([True], dtype=bool)
In [21]: x['f2']==y['f2']
Out[21]: array([True], dtype=bool)
In [22]: x==y
Out[22]: False
The question arises as to what should be returned when comparing these
arrays. One option would be an array with dtype=bool which would indicate
that each item in the array is equal in f1 and f2. Another option would be
an array with dtype
N.dtype({'names' : ['f1', 'f2'], 'formats' : [bool,bool]})
I think this second option could be very useful for some applications, where
you might want to know something like: is the (i,j)th element of this array
the same in f1 and f2 but different in f3?
Any thoughts?
Regards,
Albert
More information about the Numpy-discussion
mailing list