On this page
In school, Ax = b has the answer x = A⁻¹b, but only when A is square with a non-zero determinant. Fit a line through 50 measurements and you get 50 equations in 2 unknowns, with no exact solution. Too few measurements give infinitely many solutions. The Moore–Penrose pseudoinverse, written A⁺, gives one sensible answer in both cases.
What is the Moore–Penrose pseudoinverse?
The Moore–Penrose pseudoinverse A⁺ of an m×n matrix A is an n×m matrix that works like an inverse even when A is rectangular or singular (Wikipedia: Moore–Penrose inverse). The same article records that E. H. Moore described it in 1920, Arne Bjerhammar in 1951 and Roger Penrose in 1955, each working independently.
Penrose's paper defined it as the unique solution of a set of equations and showed that it "exists for any (possibly rectangular) matrix whatsoever with complex elements" (Penrose, 1955, Mathematical Proceedings of the Cambridge Philosophical Society). When A is invertible, A⁺ is just A⁻¹, so nothing you already know breaks.
Why does A⁺b give the least-squares and minimum-norm answer?
The vector z = A⁺b has two properties (Wikipedia, Applications):
Too many equations (no exact solution): z makes the error ‖Az − b‖ as small as any x can, so it is the least-squares solution. If several x tie for best, z is the shortest of them.
Too few equations (many solutions): z solves Ax = b, and ‖z‖ ≤ ‖x‖ for every other solution x.
Take one equation in two unknowns, x + y = 2. Every point on that line is a solution. Here A = [1 1], and A⁺ = Aᵀ(AAᵀ)⁻¹ = [1/2, 1/2]ᵀ, so A⁺b = (1, 1). That is the point on the line closest to the origin: the minimum-norm solution. A system's rank decides how many free directions it has; see finding the rank of a matrix with row echelon form.
Two shortcuts: if A has independent columns (a tall, full-rank matrix), A⁺ = (AᵀA)⁻¹Aᵀ. If A has independent rows (a wide, full-rank matrix), A⁺ = Aᵀ(AAᵀ)⁻¹.
How do you compute A⁺ from the SVD?
Every real matrix has a singular value decomposition A = UΣVᵀ, and the pseudoinverse is A⁺ = VΣ⁺Uᵀ (Wikipedia: Moore–Penrose inverse). To build Σ⁺, transpose Σ and replace each non-zero singular value σ with 1/σ. Zeros stay zero. For example, if Σ = diag(2, 0), then Σ⁺ = diag(1/2, 0). If the SVD is new to you, start with our SVD explained with a 2×2 matrix.
NumPy's `pinv` works this way: it uses the SVD and sets to zero any singular value at or below `rcond` times the largest one (NumPy documentation for numpy.linalg.pinv). The cutoff matters because 1/σ for a tiny σ is huge and amplifies noise in b; see condition number and ill-conditioned systems.
Worked example: fitting a line through three points
Find the best line y = c + mt through (0, 1), (1, 2) and (2, 4). No single line passes through all three.
Write one equation per point: c = 1, c + m = 2, c + 2m = 4. So A has rows (1, 0), (1, 1), (1, 2), the unknown is x = (c, m), and b = (1, 2, 4).
A is 3×2 with independent columns, so use A⁺ = (AᵀA)⁻¹Aᵀ. Here AᵀA has rows (3, 3) and (3, 5), with determinant 6.
Its inverse is (1/6) times the matrix with rows (5, −3) and (−3, 3).
Multiply by Aᵀ: A⁺ = (1/6) times the matrix with rows (5, 2, −1) and (−3, 0, 3). Check: A⁺A gives the 2×2 identity.
Apply it to b: A⁺b = (1/6)(5 + 4 − 4, −3 + 0 + 12) = (5/6, 3/2).
The best-fit line is y = 5/6 + 1.5t. It predicts 5/6, 7/3 and 23/6, leaving errors of 1/6, −1/3 and 1/6, whose squares add to 1/6; no other line does better. The errors add to zero, and so do the errors weighted by t: the error vector is perpendicular to both columns of A, which is what least squares means geometrically.
If you slip on a step like the 2×2 inverse, the Fermi Problem Library has a step-by-step solver that explains the reasoning.
What are the four Penrose conditions?
For a real matrix A, A⁺ is the only matrix X that satisfies all four of these (Penrose, 1955; the list as written in the Wikipedia article):
AXA = A
XAX = X
(AX)ᵀ = AX
(XA)ᵀ = XA
Conditions 3 and 4 say AA⁺ and A⁺A are symmetric. Together with the first two, they make AA⁺ the orthogonal projection onto the column space of A.
Check them on our example. A⁺A is the identity, so conditions 1, 2 and 4 hold. For condition 3, AA⁺ = (1/6) times the matrix with rows (5, 2, −1), (2, 2, 2) and (−1, 2, 5), which is symmetric. And AA⁺b = (5/6, 7/3, 23/6): projecting b onto the column space gives the line's predictions.
To revise transposes, rank and inverses before this topic, use the Fermi Concept Library, which covers every concept in mathematics alongside physics, chemistry, biology and computing.



