nearest neighbor in 2D
Andrew Dalke
adalke at mindspring.com
Tue Nov 4 03:15:12 EST 2003
Ron Adam
> for point in p:
> distance = math.sqrt((new_point[0]-point[0])**2 \
> +(new_point[1]-point[1])**2)
> I really don't know how you can make this faster. There might be a
> library that has a distance between two points function that could
> speed it up.
An easy way is to move the math.sqrt call outside the loop, since
sqrt(d1) < sqrt(d2) iff d1 < d2 (when d1,d2>=0)
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list