[Numpy-discussion] Selection of only a certain number of fields
Sat Feb 7 08:27:43 CST 2009
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
[rec[n] for n in 'name age gender'.split()]
For me that use case doesn't come up very often though.
More information about the Numpy-discussion