2017-10-03 7 views
1

을 다음과 같이 내가 그들의 인덱스와 임의 위치의 세트를 가지고 : 몇 수학 연산 후좌표 오래된 제거 및 해당 인덱스에 새로운 하나를 추가 - 파이썬

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]는 이제 pos에서 해당 인덱스로 이전 좌표 대응을 제거하고 그것으로 새로운 하나를 추가 할 필요가

[(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)]. 

로 따라 변경되었습니다. 어떻게 이것을 파이썬에서 할 수 있습니까?

답변

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)} 
+0

감사합니다, Hejun을! 그게 효과가 있었어! – ccc