依照Numpy官方中文文档:https://www.numpy.org.cn/reference/routines/linalg.html
矩阵和矢量产品:
dot(a, b[, out]) 两个数组的点积。
linalg.multi_dot(arrays) 在单个函数调用中计算两个或多个数组的点积,同时自动选择最快的求值顺序。
>>> a = np.random.random((2,3))
>>> b = np.random.random((3,2))
>>> a
array([[0.08696616, 0.53404811, 0.84211153],
[0.79415675, 0.81416954, 0.7006537 ]])
>>> b
array([[0.1884456 , 0.5936037 ],
[0.4012782 , 0.32245783],
[0.97100822, 0.59856133]])
>>> np.dot(a,b)
array([[1.04838746, 0.72788682],
[1.15670433, 1.15333394]])
>>> a.dot(b)
array([[1.04838746, 0.72788682],
[1.15670433, 1.15333394]])
>>> c = np.random.random((2,2))
>>> np.linalg.multi_dot([a,b,c])
array([[1.17414492, 1.52473513],
[1.41227193, 1.97216892]])
>>>
vdot(a, b) 返回两个向量的点积。
>>> a = np.arange(3)
>>> a
array([0, 1, 2])
>>> b = np.arange(3)
>>> b
array([0, 1, 2])
>>> np.vdot(a,b)
5
>>>
inner(a, b) 两个数组的内积。
>>> a =np.arange(4).reshape(2,2)
>>> a
array([[0, 1],
[2, 3]])
>>> b = a.copy()
>>> b
array([[0, 1],
[2, 3]])
>>> np.inner(a,b)
array([[ 1, 3],
[ 3, 13]])
我的理解是先一维内积,再二维内积,高维以此类推。
outer(a, b[, out]) 计算两个向量的外积。
>>> a = np.arange(5)
>>> b = np.arange(4)
>>> np.outer(a,b)
array([[ 0, 0, 0, 0],
[ 0, 1, 2, 3],
[ 0, 2, 4, 6],
[ 0, 3, 6, 9],
[ 0, 4, 8, 12]])
其计算方式为
Given two vectors, a = [a0, a1, ..., aM]
and
b = [b0, b1, ..., bN]
,
the outer product [1]_ is::
[[a0*b0 a0*b1 ... a0*bN ]
[a1*b0 .
[ ... .
[aM*b0 aM*bN ]]
matmul(a, b[, out]) 两个数组的矩阵乘积。
>>> a = np.arange(4).reshape(2,2)
>>> b = np.arange(6).reshape(2,3)
>>> a
array([[0, 1],
[2, 3]])
>>> b
array([[0, 1, 2],
[3, 4, 5]])
>>> np.matmul(a,b)
array([[ 3, 4, 5],
[ 9, 14, 19]])
>>>
tensordot(a, b[, axes]) 对于数组> = 1-D,沿指定轴计算张量点积。