I have two lists of vectors.
A = np.random.rand(100,2000)
B = np.random.rand(100,1000)
I need to calculate the outer product of the first entry of A with the first entry of B. Then the second, then the third and so on.
A naive loop
outers = []
for a, b in zip(A,B):
outers.append(np.outer(a,b))
takes ≈ 730 [ms] (via &&timeit
) on my computer.
In the end outers
is a 100 entry long list of 2000x1000 arrays, which is correct.
There must be a more efficient way of parallelising this task as now we actually first compute A[0]
with B[0]
and THEN A[1] B[1]
, where we could do them all independently and parallel.