From: Stefan v. d. W. <st...@su...> - 2006-06-06 21:02:30
|
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? >=20 > I've tried: >=20 > >>> import numpy > >>> x =3D [(1,2,3),(4,5,6)] > >>> numpy.array(x) > array([[1, 2, 3], > [4, 5, 6]]) > >>> numpy.array(x, dtype=3D'p') > array([[1, 2, 3], > [4, 5, 6]]) > >>> numpy.array(x, dtype=3D'O') > array([[1, 2, 3], > [4, 5, 6]], dtype=3Dobject) It works if you pre-allocate the array: In [18]: x =3D [(1,2),(3,4)] In [19]: z =3D N.empty(len(x),dtype=3D'O') In [20]: z[:] =3D x In [21]: z Out[21]: array([(1, 2), (3, 4)], dtype=3Dobject) Regards St=E9fan |