I have two arrays, the first np.array is the points from, and the second np.array are all the distances I need to calculate.
Example:
import numpy as np
from_array = np.array([(0,1), (1,1), ..., (x,y)])
to_array = np.array([(5,1), (3,1), ..., (x,y)])
What I need to do is take the first entry of the from_array
and calculate all the distances between from_array[0]
to all points in to_array, then keep the maximum distance.
So I can brute for this:
def get_distances(from_array, to_array):
results = []
distances = []
for pt in from_array:
for to in to_array:
results.append(calc_dist(pt, to))
distances.append(results)
return distances
But this is slow, I am looking for an optimized way of doing the calculation since I could have thousands of points.
The end goal is to calculate the Hausdorff Distance.
fhd = np.mean(np.min(SomeDistanceArray,axis=0))
rhd = np.mean(np.min(SomeDistanceArray,axis=1))
print (max(fhd, rhd))
I want to use numpy for this task only. My distance can either be euclidean or square euclidean distance.
So what I am looking help for is an optimized method for calculating the euclidean distance methods for two np.arrays. It should be noted that array 1 might have more rows than array 2. Means that the length of the 2D array (x,y) could be comparing 10 row to 30 rows.