[Numpy-discussion] Selection of only a certain number of fields
Travis E. Oliphant
oliphant at enthought.com
Sat Feb 7 15:45:28 EST 2009
Francesc Alted wrote:
> A Saturday 07 February 2009, Neil escrigué:
>
>> Travis E. Oliphant <oliphant <at> enthought.com> writes:
>>
>>> I've been fairly quiet on this list for awhile due to work and
>>> family schedule, but I think about how things can improve
>>> regularly. One feature that's been requested by a few people is
>>> the ability to select multiple fields from a structured array.
>>>
>>> Thus, suppose *arr* is a structured array with dtype:
>>>
>>> [('name', 'S25'),
>>> ('height', float),
>>> ('age', int),
>>> ('gender', 'S8')
>>> ]
>>>
>>> Then, newarr = arr[['name', 'age']] should be a structured array
>>> with just the name and age fields.
>>>
>> What are some common use cases for this feature?
>>
>> I use structured arrays quite a lot, but I haven't found myself
>> wanting something like this. If I do need a subset of a structured
>> array generally I use something like
>>
>> [rec[n] for n in 'name age gender'.split()]
>>
>
> Good point. However, there are still some very valid reasons for having
> an idiom like:
>
> newarr = arr[['name', 'age']]
>
> returning a record array.
>
> The first one (and most important IMO), is that newarr continues to be
> an structured array (BTW, when changed this name from the original
> record array?),
To avoid confusion with the "record array" subclass which maps
attributes to fields, Eric Jones and I have been using this terminology
for about a year.
-Travis
--
Travis Oliphant
Enthought, Inc.
(512) 536-1057 (office)
(512) 536-1059 (fax)
http://www.enthought.com
oliphant at enthought.com
More information about the NumPy-Discussion
mailing list