【发布时间】:2017-07-19 22:15:41
【问题描述】:
有没有区别
import numpy as np
np.dot(a,b)
和
a.dot(b)
在内部? 我找不到关于后一种方法的任何文档。
【问题讨论】:
-
Here's the documentation you couldn't find,主要归结为“相当于
np.dot”。但是,该方法只存在于数组上,而不是任意的类似数组。 -
np.dot([1,2,3],[4,5,6])有效,通常如果同时有函数和方法版本,则函数会在经过一些参数按摩后委托给方法。在dot案例中,两者都已编译,因此更难研究细节。使用在您的代码中看起来更漂亮的表单。 -
如果您打算在您的 numpy 代码中使用一些复杂的外部库,请考虑使用 np.dot() 变体。 autograd 至少是这样:
Similarly, we don't support the syntax A.dot(B); use the equivalent np.dot(A, B) instead. The reason we don't support the first way is that subclassing ndarray raises a host of issues. As another consequence of not subclassing ndarray, some subclass checks can break, like isinstance(x, np.ndarray) can return False. -
@user2357112:有没有人想提出一个答案,让这个问题不再悬而未决?
标签: python numpy matrix-multiplication