像这样进行乘法的最简洁的方法是什么?
# c's are scalars (or arrays like A's in general)
x = np.array([c1, c2, c3])
# A's are NumPy arrays
M = np.array([A1, A2, A3])
要得到
x*M = [c1*A1, c2*A2, c3*A3]
c 是标量,A 是 NumPy 数字多维数组(比如说,矩阵)。
示例代码:
x = np.array([1,2,3])
A = np.random.rand(2,2)
M = np.array([A,A,A])