[Numpy-discussion] Adding a flag to allow integer array access and masking

Travis Oliphant oliphant.travis at ieee.org
Tue Mar 5 20:44:14 CST 2002

I have not heard any feedback back on my proposal to add a final object to 
the extended slice syntax to current Numeric to allow for unambiguous index 
and mask-array access.  

As a modification to the proposal, suppose we just check to see if the last 
argument (of at least two) is a 0d array of type signed byte (currently this 
is illegal and will raise an error).   This number would be a flag indicating 
how to interpret the previous objects.  Of course these numbers would be 
hidden from the user who would write:

a[index_array, _I] = <values>
b = a[index_array, _I]


a[mask_array, _M] = <values>
b = a[mask_array, _M]

where _M is a  0d signed byte array indicating that the mask_array should be 
interpreted as a mask while  _I is a 0d signed byte array indicating that the 
index_array should be interpreted as a integers into the flattened version of 

Other indexing schemes could be envisioned as well

a[a1,a2,a3,_X] could be the cross product of the integer arrays a1, a2, and 
a3 for example.


a[a1, a2, a3, _Z] could select elements from a by "zipping" the sequences a1, 
a2, and a3 together to form a list of tuples to grab from a.


More information about the Numpy-discussion mailing list