t = torch.arange(24).reshape(2, 3, 4) print(t.mT.shape) # torch.Size([2, 4, 3]) — swaps the last two dims, batch untouched