gpt4 book ai didi

Python NumPy : Matrix multiplication giving wrong result

转载 作者:太空宇宙 更新时间:2023-11-04 08:47:49 25 4
gpt4 key购买 nike

我在 numpy python 中使用矩阵。我有一个矩阵 A,然后计算它的逆矩阵。现在我将 A 与其逆相乘,但我没有得到单位矩阵。谁能指出这里出了什么问题?

A = matrix([
[4, 3],
[3, 2]
]);

print (A.I) # prints [[-2 3], [ 3 -4]] - correct
print A.dot(A.T) # prints [[25 18], [18 13]] - Incorrect
print A*(A.T) # prints [[25 18], [18 13]] - Incorrect

最佳答案

您在矩阵和转置矩阵(不是逆矩阵)上使用点 ...

In [16]: np.dot(A.I, A)
Out[16]:
matrix([[ 1., 0.],
[ 0., 1.]])

通过转置,你得到了你展示的结果:

In [17]: np.dot(A.T, A)
Out[17]:
matrix([[25, 18],
[18, 13]])

关于Python NumPy : Matrix multiplication giving wrong result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38553238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com