[Numpy-discussion] Selection of only a certain number of fields

Travis E. Oliphant oliphant at enthought.com
Thu Feb 5 18:08:49 EST 2009


Hi all,

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.

It seems to me that there are two reasonable behaviors here (and 
possibly two different approaches to getting those behaviors):

1) Copy the data into a new array with a new dtype
2) Create a new array that is just a view of the old data with some of 
the fields "hidden"

I lean for having the proposed syntax do #2, but wonder what other 
people think.  

Any opinions and/or suggestions?

-Travis

-- 

Travis Oliphant
Enthought, Inc.
(512) 536-1057
http://www.enthought.com
oliphant at enthought.com




More information about the NumPy-Discussion mailing list