Composing Slices Into A Multidimensional Slice For Numpy Array Slicing
If I have two slice objects defined along one dimension each, is it possible to combine them to get a multidimensional slice object that can be used to slice a numpy array? mat = n
Solution 1:
As pointed out by @unutbu, what would be a multi-dimensional slice is actually a tuple
or list
of slice
objects, then:
slice2d = (s1, s2)
mat[slice2d]
will work. Similarly, you can extend this to 3-D, ..., N-D arrays:
slice3d = (s1, s2, s3)
...
sliceNd = (s1, s3, s3, ..., sN)
Post a Comment for "Composing Slices Into A Multidimensional Slice For Numpy Array Slicing"