a = np.array([1,2,3])
b = np.array([[1,2], [3,4], [5,6]])
对于1d和2d数组,dot和matmul做同样的事情,尽管文档的措辞有点不同
来自dot的两个病例:
- If `a` is an N-D array and `b` is a 1-D array, it is a sum product over
the last axis of `a` and `b`.
- If `a` is an N-D array and `b` is an M-D array (where ``M>=2``), it is a
sum product over the last axis of `a` and the second-to-last axis of `b`::
- If the first argument is 1-D, it is promoted to a matrix by
prepending a 1 to its dimensions. After matrix multiplication
the prepended 1 is removed.
- If the second argument is 1-D, it is promoted to a matrix by
appending a 1 to its dimensions. After matrix multiplication
the appended 1 is removed.
对于1d和2d数组,
dot
和matmul
做同样的事情,尽管文档的措辞有点不同来自
dot
的两个病例:你的
a
是(3,),而b
是(3,2):这首先适用于(2,3)和(3,)->;共享大小3维上的和积
第二种情况适用,a(3,)和a(3,2)——>;最后一个(3,)和第二个(3,2)和最后一个(3,2)的和积,同样是共享的3
“A的最后一个,B的第二个到最后一个”是基本的矩阵乘法规则。In只需要在
B
为1d时进行调整,并且没有倒数第二个matmul
规则的表述方式是添加维度,然后删除维度(3,)与(3,2)=>;(1,3)与(3,2)=>;(1,2)=>;(2,)
(2,3)与(3,)=>;(2,3)与(3,1)=>;(2,1)=>;(2,)
你可能不是在问
np.dot
,它有不同的广播规则因为您的两个示例都涉及
@
操作符,即np.matmul
的语法糖,所以我将用np.matmul
来回答您的问题答案很简单,只要引用the documentation of ^{}
(重点是我的)
相关问题 更多 >
编程相关推荐