我有一组随机位置,其指数如下:
pos = {0: (65, 0), 1: (143, 96), 2: (2, 45), 3: (128, 19), 4: (91, 34), 5: (105, 127), 6: (80, 29), 7: (148, 134), 8: (53.0, 46.5), 9: (116.0, 33.5), 10: (104.5, 87.5), 11: (62.25, 28.25), 12: (69.25, 74.75), 13: (56.75, 25.75), 14: (90.75, 78.25), 15: (93.75, 21.75), 16: (100.75, 68.25), 17: (88.25, 19.25), 18: (122.25, 71.75), 19: (116.5, 98.75)}
经过几次数学运算后,我发现点[8, 17, 20, 9, 11, 21, 10, 19, 14, 22, 16]
的坐标已相应改变为
[(64.933003914056954, 73.512353385691156), (67.609354584781386, 29.084825707397332), (65.055487297822125, 71.479138365156629), (65.634499205445252, 61.867750510493728), (65.551876571641429, 63.239283293792454), (66.366807024791072, 49.711182456213727), (65.485681419116816, 64.338102471328327), (65.308178284791879, 67.284467319880079), (67.031361074876017, 38.679499846625028), (67.286696006705057, 34.440985282832173), (65.062957777139445, 71.355123241241017)].
现在我需要删除与pos
中的那些索引对应的旧坐标,并将新的坐标添加到其中。
我怎么能用Python做到这一点?
答案 0 :(得分:2)
你可以试试这个:
pos = {0: (65, 0), 1: (143, 96), 2: (2, 45), 3: (128, 19), 4: (91, 34), 5: (105, 127), 6: (80, 29), 7: (148, 134), 8: (53.0, 46.5), 9: (116.0, 33.5), 10: (104.5, 87.5), 11: (62.25, 28.25), 12: (69.25, 74.75), 13: (56.75, 25.75), 14: (90.75, 78.25), 15: (93.75, 21.75), 16: (100.75, 68.25), 17: (88.25, 19.25), 18: (122.25, 71.75), 19: (116.5, 98.75)}
points = [8, 17, 20, 9, 11, 21, 10, 19, 14, 22, 16]
val = [(64.933003914056954, 73.512353385691156), (67.609354584781386, 29.084825707397332), (65.055487297822125, 71.479138365156629), (65.634499205445252, 61.867750510493728), (65.551876571641429, 63.239283293792454), (66.366807024791072, 49.711182456213727), (65.485681419116816, 64.338102471328327), (65.308178284791879, 67.284467319880079), (67.031361074876017, 38.679499846625028), (67.286696006705057, 34.440985282832173), (65.062957777139445, 71.355123241241017)]
for i, key in enumerate(points):
pos[key] = val[i]
pos将如下所示:
{0: (65, 0),
1: (143, 96),
2: (2, 45),
3: (128, 19),
4: (91, 34),
5: (105, 127),
6: (80, 29),
7: (148, 134),
8: (64.93300391405695, 73.51235338569116),
9: (65.63449920544525, 61.86775051049373),
10: (65.48568141911682, 64.33810247132833),
11: (65.55187657164143, 63.239283293792454),
12: (69.25, 74.75),
13: (56.75, 25.75),
14: (67.03136107487602, 38.67949984662503),
15: (93.75, 21.75),
16: (65.06295777713945, 71.35512324124102),
17: (67.60935458478139, 29.084825707397332),
18: (122.25, 71.75),
19: (65.30817828479188, 67.28446731988008),
20: (65.05548729782213, 71.47913836515663),
21: (66.36680702479107, 49.71118245621373),
22: (67.28669600670506, 34.44098528283217)}