numpy中的矩阵特殊乘法

Matrix special multiplication in numpy

我有两个数组 m1 和 m2,我想做一个特殊的乘法: 1*8 + 2*6, 3*8 + 4*6, 1*2 + 2*6, 3*2 + 4*6, ... 所以我想要这个输出。结果 = [20, 48, 14,30,..]

m1 = np.array([1,2,3,4])
m2 = np.array([8,6,2,6,2,5])

抱歉,我真的不知道该怎么做。 我认为使用这样的 for 循环:

for x in m1:

谢谢

很明显,您的标量积必须 2 乘 2 完成,因此您需要开始重塑数据:

m1 = np.array([1,2,3,4]).reshape(2,2)
m2 = np.array([8,6,2,6,2,5]).reshape(3,2)

所以现在,您需要最后一列的点积,然后将结果展平,这样做:

np.dot(m2, m1.T).reshape(-1)