【发布时间】:2019-09-24 14:09:12
【问题描述】:
我想在一个列表中找到最接近给定元组的元组。
我有一个坐标列表和一个点,我需要在列表中找到最接近我的点的项目。
类似这样的:
cords = [(455, 12), (188, 90), (74, 366), (10,10)]
point = (18, 448)
for c in cords:
dst = distance.euclidean(cords[c], point)
Output = closest distance
我尝试使用scipy.spatial.distance.euclidean,但这给出了错误:
TypeError:列表索引必须是整数或切片,而不是元组
【问题讨论】:
-
在第一次迭代中
c是元组(455, 12)-。你认为cords[(455, 12)]是什么?
标签: python list tuples euclidean-distance