[Numpy-discussion] ndarray from column data

Elaine Angelino elaine.angelino@gmail....
Wed Jul 1 20:02:53 CDT 2009

Hi there --

Is there a fast way to make a numpy ndarray from column data?

For example, suppose I want to make an ndarray with 2 rows and 3 columns of
different data types based on the following column data:

C0 = [1,2]
C1 = ['a','b']
C2 = [3.3,4.4]

I could create an empty ndarray and fill the columns one by one:

X = numpy.core.ndarray((2,), dtype='<i4,|S1,<f8')
X['f0'] = C0
X['f1'] = C1
X['f2'] = C2

The result is the same as:

X = numpy.array([(1,'a',3.3), (2,'b',4.4)], dtype='<i4,|S1,<f8')

but I would like to make X directly from the column data.

[  I know that numpy.core.records.fromarrays will produce a numpy recarray
from column data, but this of course is a recarray and not a ndarray! For

X = numpy.numpy.core.records.fromarrays([C0,C1,C2])  ]

Thanks for any help,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090701/aedbe1a7/attachment.html 

More information about the Numpy-discussion mailing list