如何找到矩形矩阵的列空间的基础? [英] How can I find a basis for the column space of a rectangular matrix?
本文介绍了如何找到矩形矩阵的列空间的基础?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出一个尺寸为m x n(其中n> m)的numpy ndarray
,如何找到线性独立的列?
Given a numpy ndarray
with dimensions m by n (where n>m), how can I find the linearly independent columns?
推荐答案
One way is to use the LU decomposition. The factor U
will be of the same size as your matrix, but will be upper-triangular. In each row of U
, pick the first nonzero element: these are pivot elements, which belong to linearly independent columns. A self-contained example:
import numpy as np
from scipy.linalg import lu
A = np.array([[1, 2, 3], [2, 4, 2]]) # example for testing
U = lu(A)[2]
lin_indep_columns = [np.flatnonzero(U[i, :])[0] for i in range(U.shape[0])]
输出:[0,2],表示A的第0列和第2列构成其列空间的基础.
Output: [0, 2], which means the 0th and 2nd columns of A form a basis for its column space.
这篇关于如何找到矩形矩阵的列空间的基础?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文