[Numpy-discussion] Advanced indexing: "fancy" vs. orthogonal

R Hattersley rhattersley at gmail.com
Wed Apr 1 05:17:01 EDT 2015

There are two different interpretations in common use of how to handle
multi-valued (array/sequence) indexes. The numpy style is to consider all
multi-valued indices together which allows arbitrary points to be
extracted. The orthogonal style (e.g. as provided by netcdf4-python) is to
consider each multi-valued index independently.

For example:

>>> type(v)<type 'netCDF4.Variable'>>>> v.shape
(240, 37, 49)>>> v[(0, 1), (0, 2, 3)].shape
(2, 3, 49)>>> np.array(v)[(0, 1), (0, 2, 3)].shape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>IndexError: shape mismatch:
indexing arrays could not be broadcast together with shapes (2,) (3,)

In a netcdf4-python GitHub issue
<https://github.com/Unidata/netcdf4-python/issues/385> the authors of
various orthogonal indexing packages have been discussing how to
distinguish the two behaviours and have currently settled on a boolean
__orthogonal_indexing__ attribute.

1. Is there any appetite for adding that attribute (with the value `False`)
to ndarray?

2. As suggested by shoyer
is there any appetite for adding an alternative indexer to ndarray where
__orthogonal_indexing__ = True? For example: myarray.ix_[(0,1), (0, 2, 3)]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150401/e8f3950c/attachment.html>

More information about the NumPy-Discussion mailing list