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

Vincent Davis vincent at vincentdavis.net
Wed Feb 24 13:12:22 EST 2010


@Stéfan van der Walt
"the constructor for structured arrays expect a list of tuples:"
Thanks you, I am not surprised it was simple.

  *Vincent Davis
720-301-3003 *
vincent at vincentdavis.net
 my blog <http://vincentdavis.net> |
LinkedIn<http://www.linkedin.com/in/vincentdavis>


2010/2/23 Stéfan van der Walt <stefan at sun.ac.za>

> Hi Vincent
>
> On 24 February 2010 07:18, 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 (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
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100224/2246f0ad/attachment.html>


More information about the SciPy-User mailing list