Stephan Hoyer <sho...@gmail.com> added the comment:

Raymond, Tal and Guido -- do any of you work routinely with multi-dimensional 
arrays?

In my experience as someone who uses Python everyday for numerical computing 
(and has been doing so for many years), the need for an operator like this 
comes up with some regularity. With multi-dimensional indexing, this allows 
lets you cut down quite a bit on boilerplate, e.g., compare

  subscript[:, 0, ::-1] vs (slice(None), 0, slice(None, None, -1))

It's absolutely true that subscript is an easy four line recipe, and indeed a 
form of this recipe is already included in both NumPy and pandas. But I think 
this is a case where the lack of a common idiom is actively harmful. I do 
multi-dimensional indexing in using at least four different libraries (pandas, 
xarray, numpy and tensorflow), and it feels wrong to use a utility from 
numpy/pandas for other projects. I could write my own version of 
operator.subscript in each project (and yes, I've done so before), but for any 
individual use case it's less hassle to write things out the long way. 

In practice, the preferred way to write such long expressions seems to be to 
redundantly repeat indexing operations, e.g.,

  x[:, 0, ::-1]
  y[:, 0, ::-1]

rather than

  index = subscript[:, 0, ::-1]
  x[index]
  y[index]

This is definitely non-ideal from a readability perspective. It's no longer 
immediately clear that these arrays are being indexed in the same way, and any 
changes would need to be applied twice.

----------
nosy: +Stephan Hoyer

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue24379>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to