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

Travis E. Oliphant oliphant@enthought....
Thu Feb 5 17:08:49 CST 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@enthought.com



More information about the Numpy-discussion mailing list