Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Matrices

Transpose, Inverse and Determinant

Flipping a matrix, undoing it, and measuring how much it stretches space. The determinant decides invertibility, appears in every change of variables, and powers normalizing flows.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Flipping a table

Turn a table on its side, so rows become columns and columns become rows. A list of 2 students × 3 subjects becomes 3 subjects × 2 students. That’s the transpose.

Undoing a machine

A machine multiplies by 4. It shows 20. What went in? You undo it by dividing by 4: 5. Some matrix machines can be undone too. The undo machine is called the inverse. But a shadow machine (A2.1-6) can’t be undone: you can’t recover the height from a shadow.

How much does it stretch?

Draw a 1 × 1 square. A machine stretches it to 2 wide and 3 tall, so now it has area 6. The number that tells you how much a machine scales area (or volume) is the determinant. If the machine squashes the square flat, the area becomes 0, and that’s exactly when the machine can’t be undone.

Linear map visualiser: a matrix warps the grid
A = [[1.0, 1.0], [0.0, 1.0]]
det A = 1.00 (area scale) · rank = 2
Ae₁Ae₂
The first column of A is where e₁ = (1, 0) lands; the second column is where e₂ = (0, 1) lands. The orange square is the image of the unit square: its area is |det A|.
📝 Quick check (Level 0)
0/3 answered
  1. 1. Flip a 2 × 3 table on its side. Its new shape is…
  2. 2. A machine squashes every square flat (area 0). Can it be undone?
  3. 3. A unit square is stretched 2× wide and 3× tall. New area?

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Transpose

A=(123456)⟹A⊤=(142536),(A⊤)ij=AjiA = \begin{pmatrix}1&2&3\\4&5&6\end{pmatrix} \quad\Longrightarrow\quad A^\top = \begin{pmatrix}1&4\\2&5\\3&6\end{pmatrix}, \qquad (A^\top)_{ij} = A_{ji}

A column vector’s transpose is a row vector, and x⊤y\mathbf x^\top\mathbf y is the dot product.

The 2×2 determinant and inverse

det⁡(abcd)=ad−bc,(abcd)−1=1ad−bc(d−b−ca)\det\begin{pmatrix}a&b\\c&d\end{pmatrix} = ad - bc, \qquad \begin{pmatrix}a&b\\c&d\end{pmatrix}^{-1} = \frac{1}{ad-bc}\begin{pmatrix}d&-b\\-c&a\end{pmatrix}

Example. det⁡(3124)=12−2=10\det\begin{pmatrix}3&1\\2&4\end{pmatrix} = 12 - 2 = 10, so the map scales areas by 10. For (4726)\begin{pmatrix}4&7\\2&6\end{pmatrix}, the determinant is 10 and the inverse is 110(6−7−24)\tfrac1{10}\begin{pmatrix}6&-7\\-2&4\end{pmatrix}. Check: AA−1=IAA^{-1} = I.

What the sign and zero mean

det⁡A\det A Meaning
>0> 0 scales area by det⁡A\det A, orientation kept
<0< 0 scales area by ∣det⁡A∣\lvert\det A\rvert, orientation flipped (like a mirror)
=0= 0 squashes the plane onto a line or point: not invertible
📝 Quick check (Level 1)
0/3 answered
  1. 1. det [[1, 2], [2, 4]] = ?
  2. 2. Inverse of [[2, 0], [0, 5]]?
  3. 3. A reflection has determinant…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Rules for the transpose

(A⊤)⊤=A,(A+B)⊤=A⊤+B⊤,(AB)⊤=B⊤A⊤(A^\top)^\top = A, \quad (A+B)^\top = A^\top + B^\top, \quad (AB)^\top = B^\top A^\top

The order reverses, as if you were taking off socks and shoes: the last one on comes off first. In ML, (XW)⊤=W⊤X⊤(XW)^\top = W^\top X^\top appears in every backpropagation derivation (A3.3).

The inverse

A−1A^{-1} exists exactly when AA is square and det⁡A≠0\det A \ne 0 (equivalently, rank nn, or kernel {0}\{\mathbf 0\}). Then AA−1=A−1A=IAA^{-1} = A^{-1}A = I. Rules: (AB)−1=B−1A−1(AB)^{-1} = B^{-1}A^{-1} (order reverses again), and (A⊤)−1=(A−1)⊤(A^\top)^{-1} = (A^{-1})^\top.

In practice, don't compute the inverse

To solve Ax=bA\mathbf x = \mathbf b, use np.linalg.solve(A, b), not inv(A) @ b. Solving directly (A2.2-4) is faster and more accurate. Inverses are a thinking tool. You rarely compute them.

Determinants of bigger matrices

The 3×33\times3 determinant can be computed by cofactor expansion along a row:

det⁡A=∑j(−1)1+ja1jdet⁡M1j\det A = \sum_{j} (-1)^{1+j}a_{1j}\det M_{1j}

Here M1jM_{1j} is AA with row 1 and column jj removed. For example, det⁡(201132112)=2(6−2)−0+1(1−3)=6\det\begin{pmatrix}2&0&1\\1&3&2\\1&1&2\end{pmatrix} = 2(6-2) - 0 + 1(1-3) = 6. Geometrically, ∣det⁡A∣\lvert\det A\rvert is the volume of the box (parallelepiped) spanned by the columns.

Key properties

det⁡(AB)=det⁡Adet⁡B,det⁡A⊤=det⁡A,det⁡(A−1)=1det⁡A,det⁡(cA)=cndet⁡A\det(AB) = \det A\det B, \quad \det A^\top = \det A, \quad \det(A^{-1}) = \frac{1}{\det A}, \quad \det(cA) = c^n\det A

Swapping two rows flips the sign. Adding a multiple of one row to another leaves it unchanged. The determinant of a triangular matrix is the product of its diagonal entries (A2.2-3).

🐍 Exercise 1: determinants and inverses
Write det2 and inv2 using the 2×2 formulas, and a general det(A) using cofactor expansion along the first row.

Where these appear

Field Use
Statistics and ML the normal equations β=(X⊤X)−1X⊤y\boldsymbol\beta = (X^\top X)^{-1}X^\top\mathbf y. det⁡Σ\det\Sigma in the Gaussian density. log⁡det⁡\log\det in Gaussian processes
Robotics inverting rotations (R−1=R⊤R^{-1} = R^\top) and poses. det⁡J=0\det J = 0 marks singular arm poses
Geometry the sign of a 2×2 determinant says whether a path turns left or right (Practice Code 3)
📝 Quick check (Level 2)
0/3 answered
  1. 1. (AB)ᵀ = ?
  2. 2. det A = 3, det B = −2. det(AB) = ?
  3. 3. A is 3 × 3 with det A = 5. det(2A) = ?

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

What a determinant really is

The determinant is the unique function of the columns of an n×nn\times n matrix that is:

  1. linear in each column separately,
  2. alternating: it changes sign when two columns are swapped (so it’s 0 if two columns are equal),
  3. normalized: det⁡I=1\det I = 1.

From these three rules you get the Leibniz formula det⁡A=∑σ∈Snsgn⁡(σ)∏iaiσ(i)\det A = \sum_{\sigma\in S_n}\operatorname{sgn}(\sigma)\prod_i a_{i\sigma(i)}, a sum over all n!n! permutations. It also gives every property above, and the geometric meaning: the signed volume of the box spanned by the columns.

Invertibility

Theorem

A square matrix is invertible if and only if det⁡A≠0\det A \ne 0.

Proof. If AA is invertible, then 1=det⁡I=det⁡(AA−1)=det⁡Adet⁡A−11 = \det I = \det(AA^{-1}) = \det A\det A^{-1}, so det⁡A≠0\det A\ne0. Conversely, if AA isn’t invertible, its columns are dependent (rank–nullity, A2.1-6). By linearity, one column can be replaced by the combination of the others without changing the determinant. That gives a matrix with a column equal to a combination of the others, and by the alternating property its determinant is 0. ∎

The inverse of a product

Theorem

If AA and BB are invertible, then (AB)−1=B−1A−1(AB)^{-1} = B^{-1}A^{-1}.

Proof. (AB)(B−1A−1)=A(BB−1)A−1=AA−1=I(AB)(B^{-1}A^{-1}) = A(BB^{-1})A^{-1} = AA^{-1} = I, and similarly in the other order. ∎

Cramer’s rule and the adjugate

A−1=1det⁡Aadj⁡(A)A^{-1} = \frac{1}{\det A}\operatorname{adj}(A), where the adjugate is the transposed matrix of cofactors. Cramer’s rule solves Ax=bA\mathbf x = \mathbf b with xi=det⁡Ai/det⁡Ax_i = \det A_i / \det A, where AiA_i is AA with column ii replaced by b\mathbf b. Both are beautiful, but slow: cofactor expansion costs O(n!)O(n!). Real software computes determinants from an LU factorization in O(n3)O(n^3) (A2.3).

Exercise 3.1: Show that a rotation matrix has determinant 1 and a reflection −1

det⁡(cos⁡θ−sin⁡θsin⁡θcos⁡θ)=cos⁡2θ+sin⁡2θ=1\det\begin{pmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{pmatrix} = \cos^2\theta + \sin^2\theta = 1. For the reflection diag⁡(−1,1)\operatorname{diag}(-1, 1), det⁡=−1\det = -1. Rotations keep area and orientation, while reflections flip orientation.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Volume of the box spanned by (1,0,0), (1,2,0), (0,1,3)?
  2. 2. How many terms are in the Leibniz formula for a 5 × 5 determinant?
  3. 3. Two equal columns force det A to be…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

The determinant in change of variables

If x=f(z)\mathbf x = f(\mathbf z) is a smooth invertible map, densities transform like this:

pX(x)=pZ(z) ∣det⁡Jf(z)∣−1p_X(\mathbf x) = p_Z(\mathbf z)\,\big\lvert\det J_f(\mathbf z)\big\rvert^{-1}

The Jacobian determinant measures how much the map stretches volume locally, and probability has to be spread out by the same factor. This one formula drives:

  • Normalizing flows (Dinh et al., 2017; Rezende and Mohamed, 2015), generative models built from invertible layers whose log⁡∣det⁡J∣\log\lvert\det J\rvert is cheap to compute (H5).
  • Integration in polar and spherical coordinates (A3.2), where dx dy=r dr dθdx\,dy = r\,dr\,d\theta.
  • Uncertainty propagation in robot state estimation (T5).
🐍 Exercise 2 (research): the change-of-variables formula
For x = A z with z ~ N(0, I), compute log p(x) through the flow formula (with −log|det A|), and check it equals the Gaussian density with covariance A Aᵀ.

Numerical reality

  • A determinant is a bad test of near-singularity. det⁡(0.1 I10)=10−10\det(0.1\,I_{10}) = 10^{-10}, yet this matrix is perfectly well-conditioned. Use the condition number or the smallest singular value instead (A2.3, A2.4).
  • Work with log-determinants. In high dimensions, det⁡\det overflows or underflows easily. np.linalg.slogdet returns log⁡∣det⁡∣\log\lvert\det\rvert stably, and that’s what Gaussian processes and flows use.

References

  1. G. Cramer (1750). Introduction à l’analyse des lignes courbes algébriques. (Cramer’s rule.)
  2. A.-L. Cauchy (1815). “Mémoire sur les fonctions qui ne peuvent obtenir que deux valeurs égales…” Journal de l’École Polytechnique, 10. (The modern theory of determinants.)
  3. D. Rezende and S. Mohamed (2015). “Variational inference with normalizing flows.” ICML.
  4. L. Dinh, J. Sohl-Dickstein, S. Bengio (2017). “Density estimation using Real NVP.” ICLR.
  5. G. Papamakarios, E. Nalisnick, D. Rezende, S. Mohamed, B. Lakshminarayanan (2021). “Normalizing flows for probabilistic modeling and inference.” JMLR, 22(57).
  6. S. Axler (2024). Linear Algebra Done Right, 4th ed. Chapter 9 (determinants via volume and multilinear forms).