python - 伪逆矩阵计算

标签 python numpy matrix-inverse

我尝试重复lectures中计算伪逆矩阵的示例:

enter image description here

我使用这个代码

from numpy import *
# https://classes.soe.ucsc.edu/cmps290c/Spring04/paps/lls.pdf
x = np.array([[-11, 2],[2, 3],[2, -1]]) 
print(x)
# computing the inverse using pinv
a = linalg.pinv(x)
print(a)

我的计算结果与讲座的结果不同。

我的结果:

[[-0.07962213  0.05533063  0.00674764]
 [ 0.04048583  0.2854251  -0.06275304]]

讲座结果:

[[-0.148  0.180  0.246]
 [ 0.164  0.189 -0.107]]

我做错了什么?请告诉我!

最佳答案

讲义中有错误。看来他们找到了伪逆

    [-1   2]
A = [ 2   3]
    [ 2  -1]

(请注意 A[0,0] 从 -11 到 -1 的变化。)以下是该版本 A 的计算结果:

In [73]: A = np.array([[-1, 2], [2, 3], [2, -1]]) 

In [74]: A
Out[74]: 
array([[-1,  2],
       [ 2,  3],
       [ 2, -1]])

In [75]: np.linalg.pinv(A)
Out[75]: 
array([[-0.14754098,  0.18032787,  0.24590164],
       [ 0.16393443,  0.18852459, -0.10655738]])

In [76]: np.linalg.pinv(A).dot([0, 7, 5])
Out[76]: array([ 2.49180328,  0.78688525])

关于python - 伪逆矩阵计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46918409/

相关文章:

python - 根据日期在 Python/Django 中过滤,忽略时间

python方法变量和在方法中创建的对象

python - 如何在对另一列进行排序的同时对一列进行分组?

numpy - 用于快速矩阵求逆的伍德伯里恒等式 - 比预期慢

Python Tkinter Canvas 更新

python - 与 numpy 不同,带有 NaN 的 Pandas 系列 np.max 不会将 NaN 显示为最大值

python - 如何防止使用 py2exe 进行不必要的导入?

python - numpy插入一个元素,保留数组维数

r - R中计算大矩阵逆的最快方法

matlab - MatLab:胆碱必须是正定的