[SciPy-User] List to record array problems, questions

Stéfan van der Walt stefan@sun.ac...
Wed Feb 24 00:18:35 CST 2010


Hi Vincent

On 24 February 2010 07:18, Vincent Davis <vincent@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 (I guess I have made a structured array) from it but it gets screwed up or I don't get it, likely both.

The constructor for structured arrays expect a list of tuples:

data_tuple = [tuple(row) for row in data]
np.array(data_tuple, dtype=[('x', int), ('y', int), ('mean', float),
('stdv', float), ('npixels', int)])

This yields

array([(0, 0, 234.0, 24.0, 25), (1, 0, 22428.0, 2378.0999999999999, 25)],
      dtype=[('x', '<i8'), ('y', '<i8'), ('mean', '<f8'), ('stdv',
'<f8'), ('npixels', '<i8')])

Regards
Stéfan


More information about the SciPy-User mailing list