Rate this Page

torch.transpose#

torch.transpose(input,dim0,dim1)Tensor#

Returns a tensor that is a transposed version ofinput.The given dimensionsdim0 anddim1 are swapped.

Ifinput is a strided tensor then the resultingouttensor shares its underlying storage with theinput tensor, sochanging the content of one would change the content of the other.

Ifinput is asparse tensor then theresultingout tensordoes not share the underlying storagewith theinput tensor.

Ifinput is asparse tensor with compressedlayout (SparseCSR, SparseBSR, SparseCSC or SparseBSC) the argumentsdim0 anddim1 must be both batch dimensions, or mustboth be sparse dimensions. The batch dimensions of a sparse tensor are thedimensions preceding the sparse dimensions.

Note

Transpositions which interchange the sparse dimensions of aSparseCSRorSparseCSC layout tensor will result in the layout changing betweenthe two options. Transposition of the sparse dimensions of a ` SparseBSR`orSparseBSC layout tensor will likewise generate a result with theopposite layout.

Parameters
  • input (Tensor) – the input tensor.

  • dim0 (int) – the first dimension to be transposed

  • dim1 (int) – the second dimension to be transposed

Example:

>>>x=torch.randn(2,3)>>>xtensor([[ 1.0028, -0.9893,  0.5809],        [-0.1669,  0.7299,  0.4942]])>>>torch.transpose(x,0,1)tensor([[ 1.0028, -0.1669],        [-0.9893,  0.7299],        [ 0.5809,  0.4942]])

See alsotorch.t().