import numpy as np
from sympy import Matrix
from sympy.matrices import randMatrix
from sympy import init_printing
init_printing()
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) \]
# a random matrix A
= randMatrix(3,4)
A A
\(\displaystyle \left[\begin{matrix}60 & 69 & 0 & 87\\19 & 82 & 75 & 30\\72 & 91 & 98 & 59\end{matrix}\right]\)
= Matrix.rref(A)
R, rref_pivots 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]\)
= A[:, rref_pivots]
C C
\(\displaystyle \left[\begin{matrix}60 & 69 & 0\\19 & 82 & 75\\72 & 91 & 98\end{matrix}\right]\)
# verify A = C*R
== C @ R A
True
References
[1]
G. Strang, Linear algebra and learning from data. Wellesley-Cambridge Press Cambridge, 2019.