4

I have an n by d matrix U and an m by d matrix V, and I want to compute the pairwise distance between each row and U and each row in V. Essentially, I want a matrix M such that M[i][j] == np.linalg.norm(U[i] - V[j]) ** 2. I have to do this computation a lot, so I want to vectorize it. Right now, it's way too slow to just use a 2d for loop. Apparently, matlab has a way of doing this using pdist2, but I'm not sure if there is a numpy equivalent.

Community
  • 1
  • 1
michaelsnowden
  • 6,031
  • 2
  • 38
  • 83

0 Answers0