Ek Esawi wrote:

> I used genfromtxt to read a file with multiple data types. The result was
> a 1D array of tuples; for example
> 
> [(1, 2, 3), (‘a’, b’, ’c’), (‘12/12/2009’, ’2/4/2014’, ‘3/4/200)’]
> 
> 
> 
> I am trying to convert this structured array to a 2D array. Is this
> possible where the data types in the 1D array are preserved?

You can specify object as the dtype for a numpy array:

>>> t = [(1, 2, 3), ('a', 'b', 'c'), ('12/12/2009', '2/4/2014', '3/4/2000')]
>>> numpy.array(t, dtype=object)
array([[1, 2, 3],
       ['a', 'b', 'c'],
       ['12/12/2009', '2/4/2014', '3/4/2000']], dtype=object)


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to