[Numpy-discussion] [Python-ideas] PEP pre-draft: Support for indexing with keyword arguments

Sturla Molden sturla.molden at gmail.com
Sun Jul 6 04:35:55 EDT 2014


Sebastian Berg <sebastian at sipsolutions.net> wrote:
 
>> Could it be useful for structured arrays?
> 
> Not sure how. The named columns seem like a decent point to me. 

NumPy is naming the fields, not the axes, so it might be more useful for
Pandas than NumPy. For example if we have an image with r,g,b data, NumPy
would not name a 'color' axis with indexes 'r', 'g' and 'b'. 

But conceptually image[i:m, j:n, field='r'] could be faster than image[i:m,
j:n]['r'] or image['r'][i:m, j:n], and perhaps also slightly more readable.
I am note sure about nested dtypes in record arrays though...

If the possibility of keyword indexing are supported in Python, there is
nothing that prevents this Pandas like extension to NumPy arrays: 

image[i:m, j:n, color='r'] 

it would require an extension of the current dtype descriptors, in order to
tell NumPy among which fields the keyword "color" would select, but it
shouldn't be undoable.


Sturla




More information about the NumPy-Discussion mailing list