I have the following bottleneck and am wondering if anyone can suggest ways to speed it up.
I have three lists x,y,z of length N. and I apply the following summation.
def abs_val_diff(x1, x2, x3, y1, y2, y3):
""" Find the absolute value of the difference between x and y """
return py.sqrt((x1 - y1) ** 2.0 + (x2 - y2) ** 2.0 + (x3 - y3) ** 2.0)
R = 0.1
sumV = 0.0
for i in xrange(N):
for j in xrange(i + 1, N):
if R > abs_val_diff(x[i], y[i], z[i],
x[j], y[j], z[j]):
sumV += 1.0
I have tried using numpy arrays, but either I am doing something wrong or there is a reduction in speed of about a factor of 2.
Any ideas would be highly appreciated.