Numpy.array with dtype works on list of tuples not on list of lists?

Alex van der Spek zdoor at
Sun Sep 18 17:55:08 CEST 2011

Why does this not work?

>>> dat=[[1,2,3],[4,5,6]]
>>> col=[('a','f4'),('b','f4'),('c','f4')]
>>> arr=numpy.array(dat,dtype=col)

Traceback (most recent call last):
  File "<pyshell#91>", line 1, in <module>
TypeError: expected a readable buffer object

But this does:

>>> dat=[(1,2,3),(4,5,6)]
>>> arr=numpy.array(dat,dtype=col)
>>> arr
array([(1.0, 2.0, 3.0), (4.0, 5.0, 6.0)], 
      dtype=[('a', '<f4'), ('b', '<f4'), ('c', '<f4')])

The only difference that the object is a list of tuples now?

Thanks for clarification,
Alex van der Spek

More information about the Python-list mailing list