Problem about reshaping a tensor

How can i convert a tensor like this:

tensor([[0, 1, 2, 3],
        [4, 5, 6, 7]])

to this

tensor([[[0, 1],
         [4, 5]],
        [[2, 3],
         [6, 7]]])

and vice versa.
I’ve tried view, but a.view(2, 2, 2) will change it to

tensor([[[0, 1],
         [2, 3]],
        [[4, 5],
         [6, 7]]])

Thanks!

You can apply following operation:
x.transpose(0,1).view(2,2,2).transpose(1,2)
where x is your tensor.

Thanks! It works as expected.