Quiz - Numpy Q10

How can you swap the first and third channel of the array of shape (3,3,3)
img = np.arange(333).reshape(3,3,3)

How does img[[2,1,0], :, :] work here?

hey @poorvika7khanna ,
Actually this is the functionality of numpy that lets us index array values.
So, as the shape is of 3 dimensions , we can actually provide 3 such indexes
and the first list/first index that we provided , i.e , [2,1,0] means we want the value at these indexes and in this order only. This is the first level.

Then you see that there are colons, that actually refers to two other dimensions of data , hence you can try indexing in them too to get the desired results.

I hope this helps.

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.