transpose on 4-d array in numpy

Viewed 3773

I have a 4d array (python) with a batch of 10000 images with 5 channels in each image. Each image is 25*25 i.e. the 4d array shape is 10000*5*25*25.

I need to transpose the images. The naive way is with nested loops:

            for i in range(np.shape(img)[0]):
                for j in range(np.shape(img)[1]):
                    img[i, j, :, :] = np.transpose(img[i, j, :, :])

but I'm sure that there is a more efficient way to do this. Do you have any idea?

Thanks!

1 Answers
Related