22 Jul 2018 22 Jul '18
22.07.18 22:03, Todd пише:
For basic slices, the normal "slice(start, stop, step)" syntax works well. But it becomes much more verbose to create more complicated slices that you want to re-use for multiple multidimensional data structures, like numpy, pandas, xarray, etc.
One idea I had was to allow creating slices by using indexing on the slice class. So for example:
x = slice[5:1:-1, 10:20:2, 5:end]
Would be equivalent to:
x = (slice(5, 1, -1), slice(10, 20, 2), slice(5, None))
Note that this wouldn't be done on a slice instance, it would be done on the slice class. The basic idea is that it would simply return whatever is given to __getitem__.