【发布时间】:2017-07-24 03:31:09
【问题描述】:
如果我有一个矩阵 A,我想得到 A 与 B 的每一行的点积。
import numpy as np
a = np.array([[1.0, 2.0],
[3.0, 4.0]])
b = np.array([[1.0, 1.0],
[2.0, 2.0],
[3.0, 3.0]])
如果目标是手动(或循环):
c = np.array([np.dot(a, b[0])])
c = np.append(c, [np.dot(a, b[1])], axis=0)
c = np.append(c, [np.dot(a, b[2])], axis=0)
print(c)
c = [[ 3. 7.]
[ 6. 14.]
[ 9. 21.]]
【问题讨论】:
-
第二列是什么?
-
我没有关注这个问题,第二栏是什么?
标签: performance python-2.7 numpy vectorization array-broadcasting