如何从矩阵中找到线性独立的行 [英] How to find linearly independent rows from a matrix

查看:593
本文介绍了如何从矩阵中找到线性独立的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从矩阵中识别线性​​独立的行?例如,

How to identify the linearly independent rows from a matrix? For instance,

第四行是独立的.

推荐答案

首先,您的第三行与第一行和第二行线性相关.但是,您的第一列和第四列是线性相关的.

First, your 3rd row is linearly dependent with 1t and 2nd row. However, your 1st and 4th column are linearly dependent.

您可以使用两种方法:

特征值

如果矩阵的一个特征值是零,则其对应的特征向量是线性相关的.文档 eig 统计特征值不一定是有序的.真的不知道结果数组中的特征值是刚刚排序还是随机排序.但是,假设特征值与您的行向量相对应,则方法为:

If one eigenvalue of the matrix is zero, its corresponding eigenvector is linearly dependent. The documentation eig stats the eigenvalues is not necessarily ordered. Don't really know if the eigenvalue in the resulting array is just sorted or have some random order. However, assuming the eigenvalues correspond to your row vectors, a method would be:

import numpy as np

matrix = np.array(
    [
        [0, 1 ,0 ,0],
        [0, 0, 1, 0],
        [0, 1, 1, 0],
        [1, 0, 0, 1]
    ])

lambdas, V =  np.linalg.eig(matrix.T)
# The linearly dependent row vectors 
print matrix[lambdas == 0,:]

Cauchy-Schwarz不等式

要测试向量的线性依赖性并找出向量,可以使用 Cauchy-Schwarz不等式.基本上,如果向量的内积等于向量范数的乘积,则向量是线性相关的.这是列的示例:

To test linear dependence of vectors and figure out which ones, you could use the Cauchy-Schwarz inequality. Basically, if the inner product of the vectors is equal to the product of the norm of the vectors, the vectors are linearly dependent. Here is an example for the columns:

import numpy as np

matrix = np.array(
    [
        [0, 1 ,0 ,0],
        [0, 0, 1, 0],
        [0, 1, 1, 0],
        [1, 0, 0, 1]
    ])

print np.linalg.det(matrix)

for i in range(matrix.shape[0]):
    for j in range(matrix.shape[0]):
        if i != j:
            inner_product = np.inner(
                matrix[:,i],
                matrix[:,j]
            )
            norm_i = np.linalg.norm(matrix[:,i])
            norm_j = np.linalg.norm(matrix[:,j])

            print 'I: ', matrix[:,i]
            print 'J: ', matrix[:,j]
            print 'Prod: ', inner_product
            print 'Norm i: ', norm_i
            print 'Norm j: ', norm_j
            if np.abs(inner_product - norm_j * norm_i) < 1E-5:
                print 'Dependent'
            else:
                print 'Independent'

测试行是一种类似的方法.

To test the rows is a similar approach.

然后您可以将其扩展为测试向量的所有组合,但是我认为此解决方案的大小会严重缩放.

Then you could extend this to test all combinations of vectors, but I imagine this solution scale badly with size.

这篇关于如何从矩阵中找到线性独立的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆