How can I store where I will slice if I have multiple arrays?
Instead of having this:
a1[5:8]
a2[5:8]
b1[5:8]
I have:
slicePart = [5:8]
a1[slicePart]
a2[slicePart]
b1[slicePart]
How can I store where I will slice if I have multiple arrays?
Instead of having this:
a1[5:8]
a2[5:8]
b1[5:8]
I have:
slicePart = [5:8]
a1[slicePart]
a2[slicePart]
b1[slicePart]
The slicing syntax is simply syntactic sugar for passing a slice
object. So you can use:
slicepart = slice(5, 8)
So, you can play around with:
In [21]: class MyObj:
...: def __getitem__(self, item):
...: print(item)
...:
In [22]: obj = MyObj()
In [23]: obj[5]
5
In [24]: obj[5:8]
slice(5, 8, None)
In [25]: obj[5, 8]
(5, 8)