[NumPy-Tickets] [NumPy] #1640: structured array incorrectly gives a broadcast error
NumPy Trac
numpy-tickets@scipy....
Mon Oct 18 15:31:30 CDT 2010
#1640: structured array incorrectly gives a broadcast error
------------------------+---------------------------------------------------
Reporter: m-paradox | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 2.0.0
Component: numpy.core | Version: devel
Keywords: structured |
------------------------+---------------------------------------------------
Changes (by m-paradox):
* keywords: => structured
* component: Other => numpy.core
Comment:
It looks like the problem is caused by two features conflicting:
* dtypes with fields are compared one field at a time, and ANDed together
* types with a shape have their shape appended to the array's shape
Here's what the code is effectively doing to get the failure, in function
_void_compare of arrayobject.c
{{{
>>> p = np.rec.recarray((2,),dtype=[('f0','f4',3),('f1','f4',1)])
>>> q = p.copy()
# in _void_compare:
>>> a = p.f0 # line 836
>>> b = q.f0 # line 841
>>> temp = a==b # line 847
>>> temp.shape # (problem here) _void_compare assumes this has the
same
(2, 3) # shape as p and q, but it doesn't
>>> res = temp # line 855
>>> a = p.f1 # line 836
>>> b = q.f1 # line 841
>>> temp = a==b # line 847
>>> temp.shape
(2,) # this is the shape that _void_compare expects
>>> temp2 = res & temp # line 858
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: shape mismatch: objects cannot be broadcast to a single shape
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1640#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list