Skip to content

← Tensor Foundations step 3 of 7

Easy Framework

Transpose a Matrix

Transpose a 2D matrix (swap rows and columns).

Input: A 2D tensor x of shape (m, n)

Output: A 2D tensor of shape (n, m) that is the transpose of x.

API Reference:

  • PyTorch: x.T, x.t(), or torch.transpose(x, 0, 1)
  • JAX: x.T or jnp.transpose(x)