[Numpy-discussion] Documentation for dtypes with named fields

Skipper Seabold jsseabold at gmail.com
Tue Mar 16 11:46:18 EDT 2010


On Tue, Mar 16, 2010 at 11:34 AM, Skipper Seabold <jsseabold at gmail.com> wrote:
> On Tue, Mar 16, 2010 at 11:20 AM, Sam Tygier
> <Sam.Tygier at hep.manchester.ac.uk> wrote:
>> Thanks for those responses.
>>
>> could the dtype pages in the numpy reference link to the basics.rec page in the user guide?
>>
>> there seem to be some gotchas in list within a list notation.
>>
>> if i have
>> a = array([0,0.1,0.2,0.3,0.4])
>> b =  array((0,0.1,0.2,0.3,0.4), dtype=[('a','f'), ('b','f'), ('c','f'), ('d','f'),('f','f')])
>>
>> then
>>>>> a[[0,1,4]]
>> array([ 0. ,  0.1,  0.4])
>>>>> a[[4,1,0]]
>> array([ 0.4,  0.1,  0. ])
>>
>> but
>>>>> b[['a','b','f']]
>> (0.0, 0.10000000149011612, 0.40000000596046448)
>>>>> b[['f','b','a']]
>> (0.0, 0.10000000149011612, 0.40000000596046448)
>>
>> so i always get the vales back in the original order. is the by design, or a bug?
>>
>
> I've been bitten by this before too and asked the same question with
> no response.  I think it's just a limitation of the design of
> structured arrays.
>

I added an example of this to:
http://docs.scipy.org/numpy/docs/numpy.doc.structured_arrays/

Skipper



More information about the NumPy-Discussion mailing list