5.4.6 · D2Scientific Computing (Python)

Visual walkthrough — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

1,990 words9 min readBack to topic

Prerequisites you may want open: NumPy arrays and broadcasting, Vector norms and metric spaces, Eigenvalues and diagonalization.


Step 1 — What a matrix does to an arrow

WHAT. A vector is just an arrow from the origin to a point. A number pair means "walk right, up". A matrix is a machine: feed it an arrow, it hands you a new arrow .

WHY start here. Every later symbol (, , ) is also just a machine acting on arrows. If we don't feel this first, the factorization is meaningless letters.

PICTURE. Look at the blue input arrow and the red output arrow. The machine below is Here each entry has a job: the top-left says "the first output coordinate takes 2 copies of "; the top-right mixes in ; the bottom row builds the second output coordinate. The arrow got both longer and tilted.

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

Step 2 — Watch the whole unit circle, not one arrow

WHAT. Instead of one arrow, feed the machine every unit-length arrow at once — the whole unit circle (all arrows of length 1 pointing every direction).

WHY. One arrow tells you almost nothing. The set of all outputs reveals the machine's personality: a circle always maps to an ellipse (a squashed, tilted circle). That ellipse is the entire secret of SVD.

PICTURE. The blue circle (inputs) becomes the red ellipse (outputs). Notice the ellipse has a longest radius and a shortest radius — and they sit at right angles to each other.

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

Step 3 — Name the ellipse's axes: the singular values

WHAT. The red ellipse has a major axis (its longest half-width) and a minor axis (its shortest half-width). Call their lengths (bigger) and (smaller). These are the singular values.

WHY these two numbers? They are the actual stretch amounts the machine applies. is the most any unit arrow can be stretched; is the least. Every other output length lives between them. That is why we always order them .

PICTURE. Yellow arrows mark the two ellipse axes; their lengths are labelled and .

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

Step 4 — Name the input directions that hit those axes:

WHAT. Which input arrows on the blue circle got stretched into the major and minor axes? Call them (maps to the long axis) and (maps to the short axis). These are the right singular vectors.

WHY they matter. They are the special input directions the machine treats cleanly — pure stretch, no confusion. Crucially, and come out perpendicular to each other on the input circle. Perpendicular in, perpendicular out — that orthogonality is the backbone of the whole factorization.

PICTURE. Green arrows sit at 90° on the blue circle; the machine sends each straight onto its matching yellow ellipse axis.

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

Step 5 — Name the output directions:

WHAT. Strip the length off the ellipse axes and keep only their directions as unit arrows: (along the major axis) and (along the minor). These are the left singular vectors.

WHY. We split each output into "which way it points" () times "how far it stretched" (). Like the 's, the 's are perpendicular to each other. Now we have four clean ingredients: perpendicular inputs , perpendicular output directions , and stretch amounts .

PICTURE. Purple/green unit arrows at 90° on the output side, each equal to its yellow axis divided by its .

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

Step 6 — Stack the vectors into matrices → the factorization appears

WHAT. Put the input vectors as columns of a matrix , the output directions as columns of , and the stretches on the diagonal of .

WHY. The single equation , written for both at once, becomes one matrix equation: Reading it: applies to both input columns; says each result is the output direction times its stretch. Now the payoff — because 's columns are perpendicular unit vectors, is orthogonal, meaning , so . Multiply both sides on the right by :

PICTURE. The blocks assembled: (rotate), (stretch), (rotate) side by side, with the arrow flowing through them.

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

WHAT. Multiply by its transpose and simplify using the factorization.

WHY. This explains the parent's claim that are eigenvalues of . Substitute and watch the rotations cancel: Term by term: because is orthogonal (its perpendicular unit columns), so it vanishes; has entries . The remaining shape is exactly a diagonalization (see Eigenvalues and diagonalization), so the diagonal entries are the eigenvalues and the columns of are the eigenvectors.

PICTURE. The cancellation shown as two rotations meeting and annihilating, leaving pure stretch-squared.

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

Step 8 — The degenerate case: a squashed (singular) matrix

WHAT. What if the machine flattens the circle onto a line? Then the ellipse has zero minor axis: .

WHY show this. SVD must survive every input, including matrices you can't invert. When : the output is one-dimensional, (matches the parent's "collapsed volume"), and is singular. np.linalg.solve would fail, but SVD keeps working — it simply reports a zero singular value. This is why SVD is the tool for Least squares regression and Principal Component Analysis (PCA): it stays sane where inversion dies.

PICTURE. The blue circle collapses to a red segment; is the segment's half-length, drawn as a flattened axis.

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det

The one-picture summary

Everything in a single frame: the input circle with perpendicular directions , flowing through rotate () → stretch () → rotate (), landing as the ellipse with axes and .

Figure — NumPy linear algebra — np.linalg.solve, eig, svd, norm, det
Recall Feynman retelling — the whole walkthrough in plain words

Imagine a stretchy machine for arrows. Feed it every arrow of length 1 — a perfect circle goes in. What comes out is always a tilted, squashed circle: an ellipse. That ellipse has a longest radius and a shortest radius, at right angles; those lengths are the singular values — the biggest and smallest stretch the machine can do. Two special input arrows (also at right angles) are the ones that landed exactly on those radii; call them . The directions the radii point are . So the machine really does just three simple things: spin the input so the special arrows line up with the axes (), stretch each axis by its (), then spin the result into place (). Stack these arrows into matrices and you literally get . If the machine flattens the circle to a line, one is zero — the matrix is singular, and SVD calmly tells you so instead of crashing.


Self-check

Circle in, what shape always comes out under a matrix?
An ellipse (squashed, tilted circle) — lines never bend under a linear map.
What geometric thing are the singular values ?
The lengths of the major and minor half-axes of the output ellipse — the max and min stretch of a unit arrow.
Why can we write (not )?
's columns are perpendicular unit vectors, so is orthogonal and .
What does tell you about ?
The circle collapsed to a line — is singular, , and its rank dropped.
How are singular values linked to eigenvalues?
; the cancellation leaves .