[Numpy-discussion] Can't assign sequence to PyObject array

Stuart I Reynolds S.I.Reynolds at cs.bham.ac.uk
Thu Apr 19 07:06:46 CDT 2001


Is there a standard workaround to allow you to assign a sequence to a
a single cell in PyObject array?

from Numeric import *

# Create a 2*5 array
a = array([range(5),range(5)], PyObject)

a[0,0] = 4 #OK - assigns an int to element 0,0
a[0,3] = {} #OK - assigns a dict

# but, trying to assign an array to element 1,4
# (or any sequence)
a[1,4] = array(range(10), Float)

The last assignment causes,
   ValueError: array too large for destination error
Doh!!

Presumably its trying to treat this as an assignment to a
slice. Is this a bug? Clearly it shouldn't be treated as a slice
assignment since a[1,4] can only refer to an atomic element in the (2D)
array, not a sequence.


Cheers,
 Stuart






More information about the Numpy-discussion mailing list