The 格拉姆施密特过程使用线性组合找到基(相当于最大的独立子集),并且二维码分解有效地模仿了这一点。
因此,做你想做的事情的一种方法是申请numpy.linalg.qr到转置,并检查非零分量R矩阵。相应的列(在转置矩阵中,即原始矩阵中的行)是独立的。
Edit经过一番搜索,我相信这次伯克利讲座解释了它,但这里有例子
import numpy as np
# 2nd column is redundant
a = np.array([[1, 0, 0], [0, 0, 0], [1, 0, 1]])
>> np.linalg.qr(a)[1] # 2nd row empty
array([[ 1.41421356, 0. , 0.70710678],
[ 0. , 0. , 0. ],
[ 0. , 0. , 0.70710678]])
# 3rd column is redundant
a = np.array([[1, 0, 0], [1, 0, 1], [0, 0, 0], ])
>> np.linalg.qr(a)[1] # 3rd row empty
array([[ 1.41421356, 0. , 0.70710678],
[ 0. , 0. , -0.70710678],
[ 0. , 0. , 0. ]])
# No column redundant
a = np.array([[1, 0, 0], [1, 0, 1], [2, 3, 4], ])
>> np.linalg.qr(a)[1] # No row empty
array([[ 2.44948974, 2.44948974, 3.67423461],
[ 0. , 1.73205081, 1.73205081],
[ 0. , 0. , 0.70710678]])