【问题标题】:Python multiplication Matrix with Matrix transpose with arrayPython乘法矩阵与矩阵转置与数组
【发布时间】:2013-06-12 05:30:49
【问题描述】:

[1]:https://upload.wikimedia.org/math/3/0/a/30aed0153521807d5a314ea76f37e723.png[1]。

我想在 Python 中使用 numpy 函数编写上述方程:

b = b - INV(J'*J) * J' * r(b)

J是矩阵,J'是J的矩阵转置, X 和 r 数组

b = b  - linalg.inv((zip(*J)).dot(J)).dot(zip(*J)).dot(r)

这不起作用...有什么建议吗?

编辑

错误:

AttributeError: 'zip' object has no attribute 'dot'

,... 我使用 Python 3.2

【问题讨论】:

  • 您能否更具体地说明什么不起作用?结果不正确,还是 python 抛出某种错误?如果出现错误,请通过将错误复制并粘贴到帖子中来编辑您的帖子。

标签: python arrays matrix numpy


【解决方案1】:

我假设您使用的是zip,因为其他关于如何在 python 中转置列表列表的帖子建议使用它。这不是您正在使用的...您正在使用numpy,因此您想使用返回数组转置的.T 属性。此外,dot 是一个 numpy 函数,而不是 nmpy 数组的方法:

b = b - np.dot(np.dot(linalg.inv(np.dot(J.T, J)), J.T), r(b))

【讨论】:

  • 谢谢...但是,我收到错误消息:“ValueError: expected square matrix”...我需要这个:INV(J'*J) * J' * r(b)。 ..和你写的不一样吧?
  • 不。我不是这样写的。 r(b) 是什么?这看起来像一个函数。与此同时,我将清理方程式。
  • 假设 r(b) 是一个数组 R ...我要怎么写呢?
  • @user1972847 只需创建一个数组R 并在我的回答中将r(b) 替换为R
  • @SethMMorton 你写了“另外,dot 是一个 numpy 函数,而不是一个 n[u]mpy 数组的方法”---好吧,dot 是一个 numpy 函数,但它也是一个 numpy 数组的方法,就像在a=np.zeros((4,2));print a.T.dot(a) 中一样,这给了我 [[ 0. 0.] [ 0. 0.]]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
  • 2016-10-12
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多