[SciPy-User] Introducing outer/orthonongal indexing to numpy

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[SciPy-User] Introducing outer/orthonongal indexing to numpy

Sebastian Berg
Hello all,

sorry for cross posting (discussion should go to the numpy list). But I
would like to get a bit of discussion on the introduction of (mostly)
two new ways to index numpy arrays. This would also define a way for
code working with different array-likes, some of which implement outer
indexing (i.e. xray and dask I believe), to avoid ambiguity.

The new methods are (names up for discussion):
  1. arr.oindex[...]
  2. arr.vindex[...]

The difference beeing that `oindex` will return outer/orthogonal type
indexing, while `vindex` would be a (hopefully) less confusing variant
of "fancy" indexing.

The biggest reason for introducing this is to provide `oindex`
for situations such as:
   >>> arr = np.arange(25).reshape((5, 5))
   >>> arr[[0, 1], [1, 2]]
   array([1, 7])
   >>> # While most might expect the result to be:
   >>> arr.oindex[[0, 1], [1, 2]]
   array([[1, 2],
          [6, 7]])

To provide backwards compatibility the current plan is to also introduce
`arr.legacy_index[...]` or similar, with the (long term) plan to force
the users to explicitly choose `oindex`, `vindex`, or `legacy_index` if
the indexing operation is otherwise not well defined.

There are still some open questions for me regarding, for example:
 * the exact time line (should we start deprecation immediately, etc.)
 * the handling of boolean indexing arrays
 * questions that might crop up about other array-likes/subclasses
 * Are there indexing needs that we are forgetting but are related?

More details the current status of my NEP, which has a lot of examples,
can be found at:
and comments about are very welcome.

There is a fully functional implementation available  at
https://github.com/numpy/numpy/pull/6075 and you can test it using
(after cloning numpy):

git fetch upstream pull/6075/head:pr-6075 && git checkout pr-6075;
python runtests.py --ipython
# Inside ipython (too see the deprecations):
import warnings; warnings.simplefilter("always")

My current hope for going forward is to get clear feedback of what is
wanted, for the naming and generally from third party module people, so
that we can polish up the NEP and the community can accept it.
With good feedback, I think we may be able to get the new attributes
into 1.11.

So if you are interested in teaching and have suggestions for the names,
or have thoughts about subclasses, or... please share your thoughts! :)



SciPy-User mailing list
[hidden email]

signature.asc (836 bytes) Download Attachment