我有一个坐标列表(x,y)。你知道吗
计算每个坐标之间距离的最有效方法是什么?你知道吗
到目前为止,我似乎要做一些事情,比如:
for coord1 in coordinates:
for coord2 in coordinates:
if (not_already_done_(coord1,coord2)):
dist = math.hypot(coord2.x - coord1.x, coord2.y - coord1.y)
save_dist(dist,coord1,coord2)
没有更快的办法吗?或者至少有更好的写作方法吗?你知道吗
Tags:
您还可以在类中嵌入
distance
函数,该函数计算一个坐标和另一个坐标之间的距离。你的课看起来像这样:然后您可以使用^{} 来获得
Coordinate
对象之间的坐标距离,正如其他人所建议的:输出:
使用itertools.combinations:
怎么样:
或:
相关问题 更多 >
编程相关推荐