Using python and numpy I have the following problem. I have two lists of 2D points which are actually Mx2
and Nx2
sized matrices (let's call A
and B
respectively). What I intend to reach is a MxN
sized matrix where the (i,j)
. th entry is the Euclidean distance between the points A[i,:]
and B[j,:]
. Simply doing a matrix multiplication np.dot(A,np.tranpose(B))
will just give me the dot products between the points so this does not work for me. Since M
and N
in the scale of tens of thousands, using for loops are prohibitively slow for me. We have numpy.apply_along_axis
but as far as I know this is not much different than a for loop under the hood. So, what would be the most fast way to do that?
Asked
Active
Viewed 52 times
0

Ufuk Can Bicici
- 3,589
- 4
- 28
- 57
-
2[`scipy.spatial.distance.pdist`](https://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.spatial.distance.pdist.html) – Mateen Ulhaq Mar 04 '20 at 11:43
-
see [`numpy.vectorize`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html) – Ma0 Mar 04 '20 at 11:43
-
I think scipy.spatial.distance_matrix solves my question – Ufuk Can Bicici Mar 04 '20 at 11:50