Returns a tensor where dimensions dim1
and dim2
have been swapped. For 2D tensors,
the convenience method of t()
is available.
> x = torch.Tensor(3,4):zero() > x:select(2,3):fill(7) -- fill column 3 with 7 > print(x) 0 0 7 0 0 0 7 0 0 0 7 0 [torch.Tensor of dimension 3x4] > y = x:transpose(1,2) -- swap dimension 1 and 2 > print(y) 0 0 0 0 0 0 7 7 7 0 0 0 [torch.Tensor of dimension 4x3] > y:select(2, 3):fill(8) -- fill column 3 with 8 > print(y) 0 0 8 0 0 8 7 7 8 0 0 8 [torch.Tensor of dimension 4x3] > print(x) -- contents of x have changed as well 0 0 7 0 0 0 7 0 8 8 8 8 [torch.Tensor of dimension 3x4]