python 中的线性无关矩阵
Linearly independent matrix in python
我有一个 15714 x 541 的矩阵,看起来这个矩阵不是线性独立的。如何删除非线性无关的列?
我尝试使用这个 post 中的解决方案:
elimination the linear dependent columns of a non-square matrix in python
但是,它说:
ValueError:项目错误长度 541 而不是 15714。
Q, R = np.linalg.qr(fixeff.T)
fixeff[np.abs(np.diag(R))>=1e-10]
fixeff就是我描述的矩阵
你可以用 scipy.linalg.qr
:
from scipy.linalg import qr
Q, R, P = qr(A, mode="economic", pivoting=True)
inv = P.argsort() # reversed order (necessary here)
good_columns = (np.abs(np.diag(R)) > 1e-10)[inv]
A = A[:,good_columns]
我有一个 15714 x 541 的矩阵,看起来这个矩阵不是线性独立的。如何删除非线性无关的列?
我尝试使用这个 post 中的解决方案: elimination the linear dependent columns of a non-square matrix in python
但是,它说: ValueError:项目错误长度 541 而不是 15714。
Q, R = np.linalg.qr(fixeff.T)
fixeff[np.abs(np.diag(R))>=1e-10]
fixeff就是我描述的矩阵
你可以用 scipy.linalg.qr
:
from scipy.linalg import qr
Q, R, P = qr(A, mode="economic", pivoting=True)
inv = P.argsort() # reversed order (necessary here)
good_columns = (np.abs(np.diag(R)) > 1e-10)[inv]
A = A[:,good_columns]