This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Stephan Hoyer
Recipients Arfrever, Stephan Hoyer, abarry, gvanrossum, josh.r, levkivskyi, llllllllll, mark.dickinson, martin.panter, ned.deily, python-dev, r.david.murray, rhettinger, serhiy.storchaka, steven.daprano, taleinat, vstinner, yselivanov
Date 2018-07-19.20:54:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1532033693.94.0.56676864532.issue24379@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-07-19 20:54:54Stephan Hoyersetrecipients: + Stephan Hoyer, gvanrossum, rhettinger, mark.dickinson, vstinner, taleinat, ned.deily, Arfrever, steven.daprano, r.david.murray, python-dev, martin.panter, serhiy.storchaka, yselivanov, josh.r, llllllllll, levkivskyi, abarry
2018-07-19 20:54:53Stephan Hoyersetmessageid: <1532033693.94.0.56676864532.issue24379@psf.upfronthosting.co.za>
2018-07-19 20:54:53Stephan Hoyerlinkissue24379 messages
2018-07-19 20:54:53Stephan Hoyercreate