<p>它们几乎相同,只有少数例外</p>
<p><code>a.dot(b)</code>和<code>np.dot(a, b)</code>完全相同。见<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.dot.html" rel="noreferrer">^{<cd3>}</a>和<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.dot.html" rel="noreferrer">^{<cd4>}</a></p>
<p>然而,看看<code>numpy.dot</code>的文档:</p>
<blockquote>
<p>If both a and b are 2-D arrays, it is matrix multiplication, but using <code>matmul</code> or <code>a @ b</code> is preferred.</p>
</blockquote>
<p><code>a @ b</code>对应于<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.matmul.html" rel="noreferrer">^{<cd7>}</a><code>dot</code>和<code>matmul</code>的区别如下:</p>
<blockquote>
<p><code>matmul</code> differs from <code>dot</code> in two important ways:</p>
<ul>
<li>Multiplication by scalars is not allowed, use <code>*</code> instead.</li>
<li>Stacks of matrices are broadcast together as if the matrices were
elements, respecting the signature <code>(n,k),(k,m)->(n,m)</code>:</li>
</ul>
<pre><code>>>> a = np.ones([9, 5, 7, 4])
>>> c = np.ones([9, 5, 4, 3])
>>> np.dot(a, c).shape (9, 5, 7, 9, 5, 3)
>>> np.matmul(a, c).shape (9, 5, 7, 3)
>>> # n is 7, k is 4, m is 3
</code></pre>
</blockquote>