liveBook · Manning

Transposition

As explained in Math and Architectures of Deep Learning

The operation of swapping a matrix’s rows and columns to produce its transpose.

Transposition swaps a matrix’s row and column indices. For an m×n matrix A, its transpose Aᵀ is n×m, with Aᵀ[i,j] = A[j,i]. A value at row 0, column 6 therefore moves to row 6, column 0. A column vector becomes a row vector, making vector transposition a special case of matrix transposition. section 2.5.1

Geometrically, transposition can reorganize an image matrix by exchanging its height and width, as when a 4×9 image representation becomes 9×4. In multiplication, transposition reverses the order of factors: (AB)ᵀ = BᵀAᵀ. This also connects dot products with matrix multiplication, since one vector can be transposed before multiplying by the other. section 2.5.1 section 2.5.3

Transposition supports several linear-algebra constructions:

  • For an orthogonal rotation matrix R, Rᵀ = R⁻¹; transposing reverses the rotation and preserves vector length. section 2.14.2
  • Multiplying a linear system by Aᵀ produces AᵀA, a square matrix used in the pseudo-inverse expression (AᵀA)⁻¹Aᵀ. section 2.12.4
  • For symmetric matrices, an eigenvector matrix S is orthogonal, so S⁻¹ = Sᵀ and diagonalization can be written A = SΛSᵀ. section 2.15

Transposing a matrix in PyTorch

Create a matrix I₄₉, transpose its dimensions with torch.transpose(I₄₉, 0, 1), and verify that every original element satisfies I₄₉[i][j] == I₄₉_t[j][i]. PyTorch’s .T notation produces the same result. section 2.7.1

Listing 2.5 Transpose
I49 = torch.stack([torch.arange(0, 72, 8), torch.arange(64, 136, 8),   #1
                torch.arange(128, 200, 8), torch.arange(192, 264, 8)])

I49_t = torch.transpose(I49, 0, 1)                                     #2

for i in range(0, I49.shape[0]):
    for j in range(0, I49.shape[1]):
        assert I49[i][j] == I49_t[j][i]                                #3


assert torch.allclose(I49_t, I49.T, 1e-5)                              #4

Inspect the complete PyTorch listing for constructing, transposing, and checking a matrix. section 2.7.1

How Math and Architectures of Deep Learning covers it

How deep it goes
Explains index-level definition, geometric effects, product identities, orthogonal matrices, pseudo-inverses, diagonalization, and PyTorch implementation.
Examples
Uses a 4×9 image matrix, vector reshaping, rotation matrices, linear systems, and PyTorch assertions as concrete demonstrations.
What it assumes
Assumes basic matrices and vectors while defining transposition formally before applying it to products, rotations, and linear systems.
What you can do after
Apply transposition in matrix calculations, verify index exchanges, and implement it with PyTorch.
How it connects
Connects transposition to matrix multiplication, dot products, orthogonal matrices, rotations, pseudo-inverse, eigenvectors, and diagonalization.

Also explained in

Compare how 6 books explain transposition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math and Architectures of Deep Learning. The section links point to the parts of the book it draws on.