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 :)
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 :)
I believe you can use transpose
and reshape
:
a.transpose([1,2,3,0]).reshape(244,244,-1)
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.