Rearrange a 5D tensor in PyTorch
I have a 5D tensor in the shape of (N,C,T,H,W). I want to rearrange it using PyTorch to the form of (N,T,HW,C). How can I do that?

Naturally you can reshape the last two dimensions of your tensor by flattening your tensor from dim=-2, this will produce a shape of (N,C,T,HW):
&gt;&gt;&gt; x.flatten(-2)

Then you can permute the dimensions around:
&gt;&gt;&gt; x.flatten(-2).permute(0,2,3,1)

