How to rearrange tensor in a certain dimension?

Thank you very much for your quick reply, which is exactly what I want.