[Tutor] list to numpy record array

Kent Johnson kent37 at tds.net
Tue Feb 23 14:30:00 CET 2010


On Mon, Feb 22, 2010 at 11:50 PM, Vincent Davis
<vincent at vincentdavis.net> wrote:
>
> I must be missing something simple. I have a list of lists data = "[['  0', '  0', '234.0', '24.0', ' 25'], ['  1', '  0', '22428.0', '2378.1', ' 25'],......" and what to make a record array from it but it gets screwed up or I don't get it, maybe both.
>
> bdata = numpy.array(data, [('x', int),('y', int),('mean',float),('stdv',float),('npixcels',int)])
> >>> bdata
> array([[(3153952, 0, 0.0, 0.0, 0), (3153952, 0, 0.0, 0.0, 0),
...
>         (3486240, 0, 0.0, 0.0, 0)]],
>
>       dtype=[('x', '<i8'), ('y', '<i8'), ('mean', '<f8'), ('stdv', '<f8'), ('npixcels', '<i8')])

All I know about RecordArrays is from reading this page:
http://www.scipy.org/RecordArrays
but it looks like you have done the right thing and created a
RecordArray. What is wrong with this result?

Kent


More information about the Tutor mailing list