[NumPy-Tickets] [NumPy] #1870: Cannot assign a list-of-lists to dtype=object ndarray if sublists are equal-length
NumPy Trac
numpy-tickets@scipy....
Mon Aug 15 12:15:10 CDT 2011
#1870: Cannot assign a list-of-lists to dtype=object ndarray if sublists are
equal-length
-------------------------+--------------------------------------------------
Reporter: mjuric | Owner: somebody
Type: defect | Status: reopened
Priority: high | Milestone: 1.6.2
Component: numpy.core | Version: 1.6.0
Resolution: | Keywords:
-------------------------+--------------------------------------------------
Comment(by mwiebe):
I believe the new example is invalid, but the error message ended up being
of poorer quality than would be ideal because of an important backwards-
compatibility decision:
http://mail.scipy.org/pipermail/numpy-discussion/2011-March/055318.html
This should illustrate the incompatibility of the assignment being done:
{{{
>>> a = numpy.zeros((5,5))
>>> v = numpy.ones((5,1))
>>> a[:,3]
array([ 0., 0., 0., 0., 0.])
>>> v
array([[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.]])
>>> a[:,3].shape
(5,)
>>> v.shape
(5, 1)
}}}
The (5,) and (5,1) get broadcast to a (5,5) shape, which is what is really
then being assigned into the (5,) array. To fix it, write the assignment
like a[:,3] = v[:,0].
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1870#comment:8>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list