[Tutor] Convert structured 1D array to 2D array

Ek Esawi esawiek at gmail.com
Fri Feb 26 22:26:22 EST 2016

The result i am looking for is a 2D array (matrix) instead of 1D array
of tuples. That's when i read a file using genfromtxt, it generated a 1D
array of n tuples (like the example shown below); each tuple has one row
from the original file. The file contains multiple data types and so i used
genfromtxt to specify data types for each column.

In another way, i just want to convert a 1D array of tuples to 2D array
where each tuple is converted multiple columns. Here is an example: the
output from genfromtxt is

[(1, 2, 3), (‘a’, b’, ’c’), (‘12/12/2009’, ’2/4/2014’, ‘3/4/200’)]

I want this be converted to:

[[1,                         2,              3],

[‘a’,                        b’,           ’c’],

[‘12/12/2009’, ’2/4/2014’, ‘3/4/200’]]

Thanks again--EKE

More information about the Tutor mailing list