I have a matrix A with dimension of 1024 * 307200 and another matrix B of dimension 1024 * 50. I am performing L2_norm on these two matrices in a nested for loop to get my final matrix C as 307200 * 50.
You can find the code below:
for i in range(307200):
for l in range(50):
C[i,l] = numpy.linalg.norm(A[:,i] - B[:,l]))
As you see the dimension of my variables is huge which is leading to a very high latency. I want to avoid this nested loop since for each values of i and l, I am using the same function.
Is there any way to optimize the above loop?
1instead: then you still have to loop over all elements. But perhaps you can make it a generator.