In [66]: a=np.array([[1, 2],
...: [2, 3],
...: [4, 5]])
...:
...: b=np.array([[1, 2, 3, 4],
...: [2, 3, 4, 5]])
...:
...:
In [67]: np.dot(a,b)
Out[67]:
array([[ 5, 8, 11, 14],
[ 8, 13, 18, 23],
[14, 23, 32, 41]])
In [68]: a@b
Out[68]:
array([[ 5, 8, 11, 14],
[ 8, 13, 18, 23],
[14, 23, 32, 41]])
In [69]: np.einsum('ij,jk',a,b)
Out[69]:
array([[ 5, 8, 11, 14],
[ 8, 13, 18, 23],
[14, 23, 32, 41]])
Трансляция умножается и суммируется:
In [71]: (a[:,:,None]*b[None,:,:]).sum(axis=1)
Out[71]:
array([[ 5, 8, 11, 14],
[ 8, 13, 18, 23],
[14, 23, 32, 41]])
In [72]: (a[:,:,None]*b[None,:,:]).shape
Out[72]: (3, 2, 4)