-2

I am trying to understand how to use np.transpose() properly.

I have a np array of shape (4,28,28,8,8). So this is 4 images of shape (224,224) that I viewed as shown by the previous shape.

I would like to revert back to (4,224,224). I feel the best way to go about is to use np.transpose() and reshape() functions. But I am hitting a roadblock as to how to revert back correctly.

Help. Please and thank you.

EDIT: (4,224,224) is 4 (this variable is subject to change as the number of images I load can change it can be 4, it can be 1000) images of shape (224,224). I used listdir() to load images. While loading I resized to the current shape of (224,224). I am going to perform operations on the shape (4,28,28,8,8) which is technically, 4 images, of shape (224,224) broken into (28,28) blocks, each containing (8,8) blocks. This shape I got by using view_as_blocks provided by scikit-image. Once I perform the operations which require that shape, I must revert back to (4,224,224). Where I am stuck.

hpaulj
  • 221,503
  • 14
  • 230
  • 353
TheTank
  • 495
  • 2
  • 9
  • 21

1 Answers1

1

What you need is probably :

b=np.swapaxes(a,3,2).reshape(4,28*8,28*8)

a beeing your array.

B. M.
  • 18,243
  • 2
  • 35
  • 54