-1

if I have a numpy array of shape

(16, 224, 224, 6)

how can I reshape it to

(224, 224, 6*16)

so that all elements are still in the new shape? P.S.:I need a numpy answer and not an answere derived from pytorch please :)

  • Does this answer your question? [Pytorch reshape tensor dimension](https://stackoverflow.com/questions/43328632/pytorch-reshape-tensor-dimension) – ilke444 Feb 24 '20 at 22:29

2 Answers2

1

I believe you can use transpose and reshape:

a.transpose([1,2,3,0]).reshape(244,244,-1)
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
0

Probably the most elegant and easy to understand way is to use einops:

from einops import rearrange
a = rearrange(a, 'b w h c -> w h (b c)')

Plus this code works on Numpy, Pytorch, Jax and Tensorflow without changes.

Valentin Goldité
  • 1,040
  • 4
  • 13