【发布时间】:2017-08-06 07:45:26
【问题描述】:
我有一个包含 5 个点的几何坐标的矩阵。
centroids = [x1,x2;...;x5,y5]
我想构建一个包含与所有其他点的距离的矩阵。
distance =
inf pt1-pt2 pt1-pt3 pt1-pt4 pt1-pt5
pt2-pt1 inf pt2-pt3 pt2-pt4 pt2-pt5
pt3-pt3 pt3-pt2 inf pt3-pt4 pt3-pt5
pt4-pt1 pt4-pt2 pt4-pt3 inf pt4-pt5
pt5-pt1 pt5-pt2 pt5-pt3 pt5-pt4 inf
我使用 inf 是因为我想用每行 [value,index]=min(distance(.....)) 的索引取最小值。
目标是有一个像这样的最终矩阵:
result =
indice_of_the_closest dist
indice_of_the_closest dist
indice_of_the_closest dist
indice_of_the_closest dist
indice_of_the_closest dist
我通过循环实现了这一点,但我需要一些帮助才能在没有循环的情况下做到这一点。
最好的问候
【问题讨论】: