[Numpy-discussion] Structured array inititialization weirdness

Erik Tollerud erik.tollerud at gmail.com
Sat Jun 20 13:04:03 EDT 2009


I've encountered an odd error I don't understand (see the case below):
the first structured array ("A" in the example) initializes from a
list of length-2 arrays with no problem, but if I give it a 2-by-2
array ("B"), it raises a TypeError... Why would it be any different to
convert the first index of the array into a list?

>>> from numpy import *
>>> from numpy.random import *
>>> dt=dtype([('a','f'),('b','f')])
>>> A=array(list(randn(2,10)),dtype=dt)
>>> B=array(randn(2,10),dtype=dt)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: expected a readable buffer object



More information about the NumPy-Discussion mailing list