Message321966
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. |
|
Date |
User |
Action |
Args |
2018-07-19 20:54:54 | Stephan Hoyer | set | recipients:
+ 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:53 | Stephan Hoyer | set | messageid: <1532033693.94.0.56676864532.issue24379@psf.upfronthosting.co.za> |
2018-07-19 20:54:53 | Stephan Hoyer | link | issue24379 messages |
2018-07-19 20:54:53 | Stephan Hoyer | create | |
|