The pseudoinverse
伪逆
Solve inconsistent and underdetermined systems through minimum-norm least squares, with exact rank-one examples and numerical cutoffs.
pseudoinverseWhen inversion cannot answer the question
Suppose two measurements are modeled by and . The equations conflict: doubling the first target would give six, not five. They also cannot distinguish the two unknowns individually. Ordinary inversion fails because is singular.
The Moore–Penrose pseudoinverse makes the desired compromise precise. First minimize the Euclidean residual ; among all minimizers, choose the one with smallest Euclidean norm. Here it gives , predictions , and squared residual . These are statements about the chosen squared-error geometry, not proof that 1.3 is the physically true value of each unknown. Deep Learning, Section 2.9
A unique matrix defined by four identities
For a real m×n matrix , its pseudoinverse is n×m and uniquely satisfies
These are the Moore–Penrose conditions. Every finite real matrix has such a pseudoinverse, including rectangular and zero matrices. If an ordinary inverse exists, the two coincide. For complex matrices, transpose becomes conjugate transpose. SciPy pinv, mathematical conditions
Using the compact rank-r SVD with positive singular values,
The formula inverts only directions that the original map preserves. In a full-factor representation, zero singular values remain zero in rather than being divided into one. The zero matrix’s pseudoinverse is the transposed-shape zero matrix.
To see why solves the stated problem, express in the orthonormal output coordinates. For each positive singular direction, choose input coordinate . Components of outside the column space cannot be matched and remain in the residual. Input null-space components do not change that residual, so setting them to zero minimizes the solution norm. Thus the least-squares solution can be nonunique, while the minimum-norm one is unique.
The products and are orthogonal projectors onto the column space and row space respectively. They are not generally identity matrices. For full column rank, ; for full row rank, . Their rank assumptions are essential, and these algebraic expressions are not a recommendation to form normal equations numerically.
An exact singular example
For nonzero vectors with , the only positive singular value is . Substitution into the SVD formula gives
This standard-library example evaluates that rank-one formula exactly using rational arithmetic and checks all four identities. It also handles a zero factor. It is a complete program for this restricted family, not a general pinv implementation; the matrix helpers assume the compatible shapes used below.
from fractions import Fraction
def rank_one_pinv(u, v):
if not u or not v or any(not isinstance(x,(int,Fraction)) for x in [*u,*v]):
raise ValueError("nonempty integer or Fraction vectors required")
u,v = list(map(Fraction,u)),list(map(Fraction,v))
a = [[x*y for y in v] for x in u]
denominator = sum(x*x for x in u)*sum(y*y for y in v)
b = [[y*x/denominator if denominator else Fraction(0) for x in u] for y in v]
return a,b
def matmul(a,b):
return [[sum(x*y for x,y in zip(row,col)) for col in zip(*b)] for row in a]
def transpose(a):
return [list(row) for row in zip(*a)]
a,b = rank_one_pinv([1,2],[1,1])
assert b == [[Fraction(1,10),Fraction(1,5)]]*2
assert matmul(matmul(a,b),a) == a
assert matmul(matmul(b,a),b) == b
assert transpose(matmul(a,b)) == matmul(a,b)
assert transpose(matmul(b,a)) == matmul(b,a)
solution = matmul(b,[[3],[5]])
assert solution == [[Fraction(13,10)],[Fraction(13,10)]]
residual = [[p[0]-y] for p,y in zip(matmul(a,solution),[3,5])]
assert sum(row[0]**2 for row in residual) == Fraction(1,5)
assert matmul(transpose(a),residual) == [[0],[0]]
assert rank_one_pinv([0,0],[1,2,3])[1] == [[0,0],[0,0],[0,0]]
# The general solver is SVD-based; this function covers rank at most one only.
Constructing the two matrices requires rational operations and storage, plus the vector norm sums. The verification multiplications add work; rational bit lengths also affect actual runtime. A general algorithm uses SVD and a specified policy for deciding which singular values count as nonzero.
Tiny singular values magnify noise
For and , the exact inverse gives . A small second measurement produced a large coefficient because its direction was divided by . Existence and uniqueness do not guarantee a useful numerical or statistical estimate.
Truncated SVD discards sufficiently small singular directions. Ridge regularization instead replaces the reciprocal factor with for . Both alter the solution; report the threshold or regularization parameter and evaluate its effect. A truncated numerical pseudoinverse is the exact pseudoinverse of the correspondingly truncated matrix, and need not satisfy exactly for the original matrix. SciPy documents an absolute-plus-relative cutoff tied to the largest singular value. SciPy threshold definition
Minimum norm also depends on units. Rescaling an input coordinate changes which coefficient vector has the smallest norm. The pseudoinverse resolves an algebraic ambiguity through a metric; it does not establish identifiability from missing information.
Separate fit from solution norm
- For and target two, what is the minimum-norm exact solution? Answer: ; also fits, but has larger norm.
- In the opening example, would fit equally well? Answer: yes, its sum is still 2.6, but it has larger norm than .
- Is always identity? Answer: no; it projects onto the column space and leaves out unmatched output directions.
- What happens to the tiny-direction example if that singular direction is truncated? Answer: the solution becomes , sacrificing the second measurement’s fit to avoid its amplification.
What the algebra leaves to the modeler
Least squares, rank-deficient regression, and inverse problems repeatedly use this construction. The SVD article explains the retained directions; orthogonal projection explains the fitted output. Regularization and validation decide whether fitting those directions is helpful. Keep the mathematical solution, numerical implementation, and empirical generalization claim separate.
Make a prediction, then check
Which solution of x₁+x₂=2 has minimum Euclidean norm?
Learning objectives
- Construct the pseudoinverse using SVD and verify the four Moore–Penrose conditions.
- Distinguish minimum residual, minimum norm, and changes caused by numerical truncation.
Prerequisites & connections
Explore related knowledge →References
- Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016 - SciPy — scipy.linalg.pinv
SciPy developers
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, derivation and numerical checks, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Exactly checked all four conditions, residual orthogonality and applicable null-space norm comparisons for 100 rational rank-at-most-one inputs.
- Recomputed (1.3,1.3), predictions (2.6,5.2) and squared residual 0.2; a truncated pseudoinverse is not presented as the original matrix’s exact inverse.
- Compared claims, assumptions, examples, exercises and citations across languages; structural validation additionally compares display equations, code and source lists.
Source locations checked:
- Deep Learning — Chapter 2: Linear Algebra · §2.9, SVD pseudoinverse and minimum-norm/least-squares interpretation
- SciPy — scipy.linalg.pinv · All four Moore–Penrose conditions, uniqueness, shape and absolute-plus-relative singular cutoff
Related topics