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

Travis Oliphant oliphant@enthought....
Thu Feb 5 22:09:26 CST 2009

Pierre GM wrote:
> On Feb 5, 2009, at 6:08 PM, Travis E. Oliphant wrote:
>> 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.
>> [...]
> +1 for #2.
> Note that we now have a drop_fields function in np.lib.recfunctions, a  
> reimplementation of the equivalent function in matplotlib. It works  
> along the lines of your proposition #1 (create a new array w/ a new  
> dtype and fill it)

After more thought, I think I was too eager in my suggestion of #2.  
It's actually not really possible to do a view the way I would want it 
to work.   It would be possible to create a data-type with 
hidden-fields, but a copy would be not "get rid of the extra data".

Thus  newarr = arr[['name', 'age']].copy() would be exactly the same 
size as arr because elements are  copied wholesale and each "row" is a 
single element in the NumPy array.    Some infrastructure would have to 
be implemented at a fundamental level to handle partial-element 
manipulation similar at least in spirit to what is needed to handle 
bit-level striding on a fundamental level.  

Also, I don't remember if we resolved how hidden fields would be shown 
in the array interface.  

So, I think that we may be stuck with #1 which at least is consistent 
with the "fancy-indexing" is a copy pattern (and is just syntatic sugar 
for capability you've already implemented in recfunctions).


More information about the Numpy-discussion mailing list