对于i = 1,...,K,我们有一个MxN矩阵A
和N维向量b_i
。当np.matmul
大时,在A
和每个b_i
之间应用乘法(K
)太慢。有什么方法可以加快我的代码速度?
import numpy as np
# for example
M = 3
N = 2
K = 10
# A\in\mathbb{R}^{M\times N}
A = np.random.random_sample((M, N))
# b_i\in\mathbb{R}^N, (i=1,\dots,K)
b_array = np.random.random_sample((K, N))
# this is slow when K is large
c_array = np.empty((K, M))
for i in range(0, K):
c_array[i] = np.matmul(A, b_array[i])
##something like...
#c_array=np.???(A,b_array)