2021年3月24日星期三

Fast way to compute min distance (haversine) between points [duplicate]

I am building an algorithm and at some point I need to compute the min distance (and index) of a point p and a list of points (centers). Ie. I need to find the closest element in centers to p.

For now, I am using fasthaversine, and my code looks as follows:

sample_array = [sample for i in range(len(centers))]  distances = haversine(sample_array, centers, unit='m')  min_index = np.argmin(distances)  

centers can be a very long list so this can take a lot of time. Anyone has anything faster to propose?

Edit: I tried the BallTree approach but it seems slower than the above. For more context, i need to run this for a lot of points p and each time the centers will be different, so I need to construct the BallTree everytime.

https://stackoverflow.com/questions/66789296/fast-way-to-compute-min-distance-haversine-between-points March 25, 2021 at 04:59AM

没有评论:

发表评论