在《 NumPy v1.15参考指南》中,numpy.dot的文档使用“和积”的概念。
即,我们阅读以下内容:
- 如果a是ND数组,b是一维数组,则它是a和b的最后一个轴上的总和。
- 如果a是ND数组而b是MD数组(其中M> = 2),则它是a的最后一个轴和b的倒数第二个轴的和积:
dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
“和积”概念的定义是什么?
(例如,在Wikipedia上找不到这样的定义。)
https://zh.wikipedia.org/wiki/Matrix_multiplication
That is, the entry c[i,j] of the product is obtained by multiplying
term-by-term the entries of the ith row of A and the jth column of B,
and summing these m products. In other words, c[i,j] is the dot product
of the ith row of A and the jth column of B.
https://zh.wikipedia.org/wiki/点产品
Algebraically, the dot product is the sum of the products of the
corresponding entries of the two sequences of numbers.
在早期的数学课程中,您是不是通过一根手指在的行A
上下滑动来学习矩阵乘积,B
将数字对混合并求和?该动议是我对如何使用该产品的直觉的一部分。
对于1D第二个参数的情况下,np.dot
并np.matmul
产生同样的事情,但不同的形容行动:
如果a
是ND数组且b
是一维数组,则它是和的最后一个轴的a
和b
。
如果第二个参数是1-D,则通过在其维数后附加1来将其提升为矩阵。矩阵相乘后,将附加的1删除。
在[103]中:np.dot([[1,2 ,, [3,4]],[1,2])Out [103]:array([5,11])在[104]中:np.matmul ([[1,2],[3,4]],[1,2])Out [104]:数组([5,11])
将尺寸附加到B
,可以:
In [105]: np.matmul([[1,2],[3,4]], [[1],[2]])
Out[105]:
array([[ 5],
[11]])
最后一个是(2,2)和(2,1)=>(2,1)
有时用以下einsum
术语表达动作会更清晰:
In [107]: np.einsum('ij,j->i', [[1,2],[3,4]], [1,2])
Out[107]: array([ 5, 11])
j
,两个数组的最后一个轴都是“求和”的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句