【发布时间】:2022-01-01 07:18:09
【问题描述】:
我正在尝试想出一个快速的方法来calculate l2 distance between the rows of two 2d numpy arrays。所以第一个二维numpy数组是7000 x 100,第二个二维numpy数组是4000 x 100。
我想得到一个4000 x 7000 的矩阵,其中每个(i, j) 条目是一个l2 norm between ith row of second 2d numpy array and jth row of first 2d numpy array。
我假设我可能必须使用 numpy.linalg.norm,但不太确定如何对操作进行矢量化。
感谢您的帮助!如果问题有任何不清楚之处,请告诉我。
【问题讨论】:
-
这能回答你的问题吗? Fastest pairwise distance metric in python
标签: arrays python-3.x numpy-ndarray