AI視覺網奇 2021-08-15 03:55:30 阅读数:213
import numpy as np
a =np.array([[1,2] ,[3 ,4],[5,6]])
b =np.array( [[5 ,6] ,[7 ,8],[9,10]])
print (np.matmul(a ,b.T))
print (np.dot(b ,a.T))
結果:
m:
[[ 17 23 29]
[ 39 53 67]
[ 61 83 105]]
n:
[[ 17 39 61]
[ 23 53 83]
[ 29 67 105]]
m轉置一下就是n。
1.二者都是矩陣乘法。
2.np.matmul中禁止矩陣與標量的乘法,但是np.dot可以。
3.在矢量乘矢量的內積運算中,np.matmul與np.dot沒有區別。
4.np.matmul中,多維的矩陣,將前n-2維視為後2維的元素後,進行乘法運算。
>>>import numpy as np
>>>a=np.array([1,2,3])
>>> b=np.array([1,0,1])
>>> b
array([1, 0, 1])
>>> np.dot(a,b)
4
>>> np.matmul(a,b)
4
>>> np.dot(a,2) #dot可以進行標量之間的乘法
array([2, 4, 6])
>>> np.matmul(a,2) #matmul不能進行標量之間的乘法
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Scalar operands are not allowed, use '*' instead
原文鏈接:https://blog.csdn.net/dream6104/article/details/89705177
版权声明:本文为[AI視覺網奇]所创,转载请带上原文链接,感谢。 https://gsmany.com/2021/08/20210815035505483q.html