On Tue, Jun 06, 2006 at 01:05:43PM -0500, Travis N. Vaught wrote:
> 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)

It works if you pre-allocate the array:

In [18]: x = [(1,2),(3,4)]

In [19]: z = N.empty(len(x),dtype='O')

In [20]: z[:] = x

In [21]: z
Out[21]: array([(1, 2), (3, 4)], dtype=object)

Regards
Stéfan


_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to