if a.shape[0] != NUM_FEATURES:
    to_calc = diff
else:
    to_calc = np.multiply(FTR_WEIGHTS, diff)
if not cache.get(to_calc):
    cache[to_calc] = np.linalg.norm(to_calc)
return cache[to_calc]
How to improve the performance of this tiny distance Python function