I have this numpy
code to try and compute the euclidean distance between b
and EVERY row of a
. I can’t get the speed to faster than 3.5s. But the best Julia solution I found can do this in about 75ms. Which is like almost 50x faster!
I have to admit I have never used numba but have heard lots of good things about it. I will start looking into how to write this in numba, but given it’s a simple problem, I wonder if anyone can help give me some example code to work from? Do I just write a loop and Numba will @jit
it?
my numpy code
import numpy as np
# generate
a = np.random.rand(4000000, 128)
b = np.random.rand(128)
print(a.shape)
print(b.shape)
def lin_norm_ever(a, b):
return np.linalg.norm(a - b, axis=1)
import time
t = time.time()
res = lin_norm_ever(a, b)
print(res.shape)
elapsed = time.time() - t
print(elapsed)