Combination of slicing and array index in numpy

60 views Asked by At

Looking at the answers to this question: How to understand numpy's combined slicing and indexing example

I'm still unable to understand the result of indexing with a combination of a slice and two 1d arrays, like this:

>>> m = np.arange(36).reshape(3,3,4)
>>> m
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7],
        [ 8,  9, 10, 11]],

       [[12, 13, 14, 15],
        [16, 17, 18, 19],
        [20, 21, 22, 23]],

       [[24, 25, 26, 27],
        [28, 29, 30, 31],
        [32, 33, 34, 35]]])

>>> m[1:3, [2,1],[2,1]]
array([[22, 17],
       [34, 29]])

Why is the result equivalent to this?

np.array([
         [m[1,2,2],m[1,1,1]],
         [m[2,2,2],m[2,1,1]]
         ])
0

There are 0 answers