gpt4 book ai didi

python - Numpy转置乘法问题

转载 作者:IT老高 更新时间:2023-10-28 21:11:42 29 4
gpt4 key购买 nike

我试图找到矩阵的特征值乘以它的转置,但我无法使用 numpy 来完成。

testmatrix = numpy.array([[1,2],[3,4],[5,6],[7,8]])
prod = testmatrix * testmatrix.T
print eig(prod)

我预计该产品会得到以下结果:

5    11    17    23
11 25 39 53
17 39 61 83
23 53 83 113

和特征值:

0.0000
0.0000
0.3929
203.6071

当将 testmatrix 与其转置相乘时,我得到 ValueError: shape mismatch: objects cannot be broadcast to a single shape

这在 MatLab 中有效(乘法,而不是代码),但我需要在 python 应用程序中使用它。

谁能告诉我我做错了什么?

最佳答案

您可能会发现 tutorial有用,因为您了解 MATLAB。

另外,尝试将 testmatrixdot() 函数相乘,即 numpy.dot(testmatrix,testmatrix.T)

显然 numpy.dot用于数组之间进行矩阵乘法! * 运算符用于逐元素乘法(MATLAB 中的 .*)。

关于python - Numpy转置乘法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3213105/

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