Slicing in 3D array

for img = np.arange(333).reshape(3,3,3)
can someone please explain the meaning of img[:, ::-1] step wise?

hey @nikhil_0406 ,
when we just do array[:] , it means we want to access all the components.
So taking the current case ,
we have an array of shape (2,3,4) , we can say it as a bunch of 2 arrays each of shape ( 3,4 ) concatenated vertically.

So , on doing img[:,something here] will mean that , we need to perform some operation on each array in this full array , means performing same operation on both ( 3,4 ) shape arrays.
and you know that ::-1 is a special operation to reverse.
so currently the first array inside this big array is

[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]]

which means on applying the reverse operation it gets changed as

[[ 8 9 10 11] [ 4 5 6 7] [ 0 1 2 3]]

simply a reversion on indexs [1,2,3] to [3,2,1].

The same thing happen with the other array also and in this way this array gets internally reversed.

I hope this helps.
Thank You and Happy Learning :slightly_smiling_face:.

1 Like

::-1 is a special operation to reverse. I learned today, thankyou.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.