[Numpy-discussion] Nested recarrays with subarrays and loadtxt: a bug in loadtxt?

Fernando Perez fperez.net@gmail....
Wed May 27 18:09:08 CDT 2009

Hi Stefan,

2009/5/27 Stéfan van der Walt <stefan@sun.ac.za>:
> Hi Fernando
> 2009/5/27 Fernando Perez <fperez.net@gmail.com>:
>> I'm wondering if the code below illustrates a bug in loadtxt, or just
>> a 'live with it' limitation.
> I'm not sure whether this is a bug or not.
> By specifying the dtype
>> dt = dtype(dict(names=['name','x','y','block'],
>>                formats=['S4',float,float,(int,(2,3))]))
> you are saying "column four contains 6 integers", which is a bit of a
> strange notion.  If you want this to be interpreted as "the last 6
> columns should be stored in block", then a simple modification to
> flatten_dtype should do the trick.

Well, since dtypes allow for nesting full arrays in this fashion,
where I can say that the 'block' field can have (2,3) shape, it seems
like it would be nice to be able to express this nesting into loading
of plain text files as well.

The idea would be that any nested dtype like the above would be
expanded out for reading purposes into columns, so that the dt spec is
interpreted in the second form you provided.

So I'd give it a mild +0.5 for this modification if it's indeed easy,
since it seems to make loadtxt more convenient to use for this class
of uses.  But if people feel it's stretching things too far, there's
always either the two-pass hack I used or the custom converter Pierre

Thanks for the feedback!



More information about the Numpy-discussion mailing list