[Numpy-discussion] array of tuples

Travis N. Vaught travis at enthought.com
Tue Jun 6 13:05:43 CDT 2006


I'd like to construct an array of tuples and I'm not sure how (without 
looping).  Is there a quick way to do this with dtype?

I've tried:

 >>> import numpy
 >>> x = [(1,2,3),(4,5,6)]
 >>> numpy.array(x)
array([[1, 2, 3],
       [4, 5, 6]])
 >>> numpy.array(x, dtype='p')
array([[1, 2, 3],
       [4, 5, 6]])
 >>> numpy.array(x, dtype='O')
array([[1, 2, 3],
       [4, 5, 6]], dtype=object)

Thanks,

Travis





More information about the Numpy-discussion mailing list