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

Peter Otten __peter__ at web.de
Sat Feb 27 03:01:07 EST 2016

Ek Esawi wrote:

> Thanks for the input. I tried your idea but i did not work; l got 1D array
> of tuples; the same as the original array. I think b/c genfromtxt creates
> an array and so it's already an array object-if i understand it correctly.
> Your idea works well for a list which i tested but i want to an n x n 2D
> array from 1D n x 1 tuples, each tuple has n elements,.

Be creative, find a workaround like

a = [...]
b = numpy.array([tuple(row) for row in a], dtype=object)

Or try 

b = numpy.array(a, dtype=(object, object))

More information about the Tutor mailing list