Matrix rank factorization

Linear Algebra
Published

October 10, 2021

A matrix can be factorized as \(A = C*R\), where \(C\) is a basis of the column space, and \(R\) is row-reduced echelon form of \(A\) without zero rows [1]. All three matrices have the same rank

\[ rank(A) = rank(C) = rank(R) \]

import numpy  as np
from sympy import Matrix
from sympy.matrices import randMatrix
from sympy import init_printing
init_printing()
# a random matrix A
A = randMatrix(3,4)
A

\(\displaystyle \left[\begin{matrix}60 & 69 & 0 & 87\\19 & 82 & 75 & 30\\72 & 91 & 98 & 59\end{matrix}\right]\)

R, rref_pivots = Matrix.rref(A)
print(f"pivots: {rref_pivots}\n" )
R
pivots: (0, 1, 2)

\(\displaystyle \left[\begin{matrix}1 & 0 & 0 & \frac{34637}{52797}\\0 & 1 & 0 & \frac{36451}{52797}\\0 & 0 & 1 & - \frac{27509}{52797}\end{matrix}\right]\)

C = A[:, rref_pivots]
C

\(\displaystyle \left[\begin{matrix}60 & 69 & 0\\19 & 82 & 75\\72 & 91 & 98\end{matrix}\right]\)

# verify A = C*R
A == C @ R
True

References

[1]
G. Strang, Linear algebra and learning from data. Wellesley-Cambridge Press Cambridge, 2019.