Clear explanation needed for Numpy 3D array indexing

Hello,

In a 3D array using numpy, I am unable to understand the output for below code. Please help.

Code:
a = np.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 ] ] )
result=a[ 2 :: 2, :: 2 ]
print(result)

Output:
[ [ 12 14 16 ],
[ 24 26 28 ] ]

Hey.

A couple of observations:

  • Your code doesn’t run. Please fix it.
  • What I think is your intended array isn’t 3-dimensional.