[Numpy-discussion] dtype subarray comparison
Pauli Virtanen
pav@iki...
Thu Oct 21 16:11:07 CDT 2010
Thu, 21 Oct 2010 13:33:21 -0700, Mark Wiebe wrote:
[clip]
> There's a bug in my current patch with regard to this then, as follows:
>
> >>> x = np.array([(0,),(0,),(1,)],dtype=[('a','f8',(1,))])
>>>> y = np.array([[(0,)],[(1,)]],dtype=[('a','f8',(1,))]) x==y
> array([ True, False, False], dtype=bool)
>>>> y==x
> array([[ True, True, False],
> [False, False, True]], dtype=bool)
Also, it is not correct to assume the dimensions are added to the end:
>>> x = np.zeros((2,3),dtype=[('a','f8',(4,))]).T
>>> x.shape
(3, 2)
>>> x['a'].shape
(4, 3, 2)
There's a special branch in the field access code that does this for
Fortran-order arrays. Or, more precisely, arrays with the fortran-order
flag set. (IIRC, there are some ways to create arrays in Fortran order so
that the flag does not get set.)
This seems to be somewhat of a mis-feature to me -- it makes predicting
code behavior difficult to anticipate.
--
Pauli Virtanen
More information about the NumPy-Discussion
mailing list