2013-04-26 136 views
3

我列出nLedgers列表 - 點的3D雲:地圖和用(X,Y),(X,Z)和(Y,Z)對和相關的X工作,Y或Z座標

[nodeID, X, Y, Z] 

多行。一些節點將具有相同的座標XY,並且不同的座標爲Z

我想先識別不同的Z座標,它們有相同的座標XY。 然後同樣爲X,最後爲Y

然後,使用這些(X,Y)(X,Z)(Y,Z)雙和不同ZYX水平我想變更的第二列表(nodes)的xy座標。

的更改應遵守以下:

1) For x,y,z in `nodes`, if x=X and y=Y and Z level 1 <=z< Z level 2: 
    change x and y coordinates between consecutive `Z` levels, for each pair of `(X,Y)` coordinates. 

2) For x,y,z in `nodes`, if x=X and Y level 1 <=y< Y level 2: 
    change x coordinates between consecutive `Y` levels, for each pair of `(Y,Z)` coordinates. 

3) For x,y,z in `nodes`, if y=Y and X level 1 <=x< X level 2: 
    change y coordinates between consecutive `X` levels, for each pair of `(X,Z)` coordinates. 

任何幫助表示讚賞。

根據以往的帖子中,我有以下代碼:

from ast import literal_eval 
nLedgers=[[literal_eval(x) for x in item] for item in nLedgers] #transform list of strings to list of floats 
nodes=[[literal_eval(x) for x in item] for item in nodes] 

NewNodesCoord = [] 
dirX=1 #integer that changes the direction (X,Y) of the vector to change the x and y coordinates 
dirY=1-dirX 
newy1=0 #float that stores the new y coordinate at x=X1 and z=Z 
newy2=0 #float that stores the new y coordinate at x=X2 (X2>X1) and z=Z 
newx1=0 #float that stores the new x coordinate at y=Y1 and z=Z 
newx2=0 #float that stores the new x coordinate at y=Y2 (Y2>Y1) and z=Z 

from collections import defaultdict 
dic1=defaultdict(list) #dictionary of X and Y pairs 
dic2=defaultdict(list) #dictionary of X and Z pairs 
dic3=defaultdict(list) #dictionary of Y and Z pairs 

for id,x,y,z in nLedgers: 
    dic1[(x,y)].append((id,z)) 
for key in dic1: 
    dic1[key].sort(key=lambda x:float(x[1])) 

for id,x,y,z in nLedgers: 
    dic2[(x,z)].append((id,y)) 
for key in dic2: 
    dic2[key].sort(key=lambda x:float(x[1])) 
#print dic2 

for id,x,y,z in nLedgers: 
    dic3[(y,z)].append((id,x)) 
for key in dic2: 
    dic3[key].sort(key=lambda x:float(x[1])) 
#print dic3 

newNodes=[] #list with changed coordinates 
for i,row in enumerate(nodes): #same X,Y, different Z 
    id,x,y,z=row 
    z_levels=[item[1] for item in dic1[(x,y)]] 
    for k,l in zip(z_levels,z_levels[1:]): 
     if k<=z<l: 
      nodes[i][1]=x+((l-k)/400*sin(pi*(z-k)/l)+max(z_levels)/800*(z/max(z_levels)))*dirX 
      nodes[i][2]=y+((l-k)/400*sin(pi*(z-k)/l)+max(z_levels)/800*(z/max(z_levels)))*dirY 
      nodes[i][3]=z 
      newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]]) 
#   break 

for i,row in enumerate(nodes): #same X, different Y 
    id,x,y,z=row 
    y_levels=[item[1] for item in dic2[(x,z)]] 
    z_levels=[item[1] for item in dic1[(x,y)]] 
    for k,l in zip(y_levels,y_levels[1:]): 
     if x==dic2.keys()[0][0] and k<y<l: 
      for m,n in zip(z_levels,z_levels[1:]): 
       if m==z and y==k: 
        newx1=x+((n-m)/400*sin(pi*(z-m)/n)+max(z_levels)/800*(z/max(z_levels)))*dirX 
       if m==z and y==l: 
        newx2=x+(n-m)/400*sin(pi*(z-m)/n)+max(z_levels)/800*(z/max(z_levels)) 
      nodes[i][1]=x+(y-k)*(newx2-newx1)/(l-k)+newx1 
      nodes[i][2]=y 
      nodes[i][3]=z 
      newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]]) 

for i,row in enumerate(nodes):#same Y, different X 
    id,x,y,z=row 
    x_levels=[item[1] for item in dic3[(y,z)]] 
    z_levels=[item[1] for item in dic1[(x,y)]] 
    for k,l in zip(x_levels,x_levels[1:]): 
#  print dic3.keys()[0][0] 
     if y==dic3.keys()[0][0] and k<x<l: #same X, different Y 
      for m,n in zip(z_levels,z_levels[1:]): 
       if m==z and y==k: 
        newy1=y+((n-m)/400*sin(pi*(z-m)/n)+max(z_levels)/800*(z/max(z_levels)))*dirY 
       if m==z and y==l: 
        newy2=y+((n-m)/400*sin(pi*(z-m)/n)+max(z_levels)/800*(z/max(z_levels)))*dirY 
      nodes[i][1]=x 
      nodes[i][2]=y+(y-k)*(newy2-newy1)/(l-k)+newy1 
      nodes[i][3]=z 
      newNodes.append([nodes[i][0], nodes[i][1], nodes[i][2], nodes[i][3]]) 

的第一個變化是工作(在X,Y對),另外兩個是不工作。我在dic2.keys()[0][0]有問題。我想循環訪問dic2的鍵,並將第一個鍵的值與x進行比較。

+0

'Z =排序(Z)'什麼也不做,(你只是將名字'z'綁定到自己的排序版本,而不是改變它的內容)改爲'z.sort()' – jamylak 2013-04-26 09:34:03

+0

@jamylak:我得到這個錯誤:'z.sort() AttributeError:'str'object has沒有屬性'sort'' – jpcgandre 2013-04-26 09:36:45

+0

噢,我忘記了,你正在使用'set',等待它爲什麼說'st那麼?它變成了一個字符串 – jamylak 2013-04-26 09:37:42

回答

1
from collections import defaultdict 
data1=[['173', '0.', '0.', '0.'], ['183', '1000.', '0.', '0.'], ['184', '0.', '1000.', '0.'], ['194', '1000.', '1000.', '0.'], ['195', '0.', '0.', '1000.'], ['205', '1000.', '0.', '1000.'], ['206', '0.', '1000.', '1000.'], ['216', '1000.', '1000.', '1000.'], ['217', '0.', '0.', '2000.'], ['227', '1000.', '0.', '2000.'], ['228', '0.', '1000.', '2000.'], ['238', '1000.', '1000.', '2000.'], ['239', '0.', '0.', '3000.'], ['249', '1000.', '0.', '3000.'], ['250', '0.', '1000.', '3000.'], ['260', '1000.', '1000.', '3000.'], ['261', '0.', '0.', '4000.'], ['271', '1000.', '0.', '4000.'], ['272', '0.', '1000.', '4000.'], ['282', '1000.', '1000.', '4000.'], ['283', '0.', '0.', '0.'], ['293', '0.', '1000.', '0.'], ['294', '1000.', '0.', '0.'], ['304', '1000.', '1000.', '0.'], ['305', '0.', '0.', '1000.'], ['315', '0.', '1000.', '1000.'], ['316', '1000.', '0.', '1000.'], ['326', '1000.', '1000.', '1000.'], ['327', '0.', '0.', '2000.'], ['337', '0.', '1000.', '2000.'], ['338', '1000.', '0.', '2000.'], ['348', '1000.', '1000.', '2000.'], ['349', '0.', '0.', '3000.'], ['359', '0.', '1000.', '3000.'], ['360', '1000.', '0.', '3000.'], ['370', '1000.', '1000.', '3000.'], ['371', '0.', '0.', '4000.'], ['381', '0.', '1000.', '4000.'], ['382', '1000.', '0.', '4000.'], ['392', '1000.', '1000.', '4000.'], ['436', '-1000.', '0.', '0.'], ['446', '0.', '0.', '0.'], ['447', '-1000.', '1000.', '0.'], ['457', '0.', '1000.', '0.'], ['458', '-1000.', '1000.', '1000.'], ['468', '0.', '1000.', '1000.'], ['469', '-1000.', '1000.', '2000.'], ['479', '0.', '1000.', '2000.'], ['480', '-1000.', '1000.', '3000.'], ['490', '0.', '1000.', '3000.'], ['491', '-1000.', '0.', '0.'], ['501', '-1000.', '1000.', '0.'], ['502', '-1000.', '1000.', '4000.'], ['512', '0.', '1000.', '4000.'], ['513', '-1000.', '0.', '1000.'], ['523', '0.', '0.', '1000.'], ['524', '-1000.', '0.', '2000.'], ['534', '0.', '0.', '2000.'], ['535', '-1000.', '0.', '3000.'], ['545', '0.', '0.', '3000.'], ['546', '-1000.', '0.', '4000.'], ['556', '0.', '0.', '4000.'], ['557', '-1000.', '0.', '1000.'], ['567', '-1000.', '1000.', '1000.'], ['568', '-1000.', '0.', '3000.'], ['578', '-1000.', '1000.', '3000.'], ['579', '-1000.', '0.', '2000.'], ['589', '-1000.', '1000.', '2000.'], ['590', '-1000.', '0.', '4000.'], ['600', '-1000.', '1000.', '4000.'], ['687', '0.', '2000.', '0.'], ['697', '1000.', '2000.', '0.'], ['698', '0.', '2000.', '1000.'], ['708', '1000.', '2000.', '1000.'], ['709', '0.', '2000.', '2000.'], ['719', '1000.', '2000.', '2000.'], ['720', '0.', '2000.', '3000.'], ['730', '1000.', '2000.', '3000.'], ['731', '0.', '2000.', '4000.'], ['741', '1000.', '2000.', '4000.'], ['742', '0.', '1000.', '0.'], ['752', '0.', '2000.', '0.'], ['753', '1000.', '1000.', '1000.'], ['763', '1000.', '2000.', '1000.'], ['764', '1000.', '1000.', '3000.'], ['774', '1000.', '2000.', '3000.'], ['775', '1000.', '1000.', '0.'], ['785', '1000.', '2000.', '0.'], ['786', '1000.', '1000.', '2000.'], ['796', '1000.', '2000.', '2000.'], ['797', '1000.', '1000.', '4000.'], ['807', '1000.', '2000.', '4000.'], ['808', '-1000.', '1000.', '0.'], ['818', '-1000.', '2000.', '0.'], ['819', '0.', '1000.', '1000.'], ['829', '0.', '2000.', '1000.'], ['830', '0.', '1000.', '2000.'], ['840', '0.', '2000.', '2000.'], ['841', '0.', '1000.', '3000.'], ['851', '0.', '2000.', '3000.'], ['852', '0.', '1000.', '4000.'], ['862', '0.', '2000.', '4000.'], ['863', '-1000.', '2000.', '0.'], ['873', '0.', '2000.', '0.'], ['874', '-1000.', '2000.', '1000.'], ['884', '0.', '2000.', '1000.'], ['885', '-1000.', '2000.', '2000.'], ['895', '0.', '2000.', '2000.'], ['896', '-1000.', '2000.', '3000.'], ['906', '0.', '2000.', '3000.'], ['907', '-1000.', '2000.', '4000.'], ['917', '0.', '2000.', '4000.'], ['918', '-1000.', '1000.', '1000.'], ['928', '-1000.', '2000.', '1000.'], ['929', '-1000.', '1000.', '3000.'], ['939', '-1000.', '2000.', '3000.'], ['940', '-1000.', '1000.', '2000.'], ['950', '-1000.', '2000.', '2000.'], ['951', '-1000.', '1000.', '4000.'], ['961', '-1000.', '2000.', '4000.']] 
data2=[['1', '0.', '0.', '-100.'], ['2', '0.', '0.', '0.'], ['3', '0.', '0.', '4000.'], ['4', '0.', '0.', '4100.'], ['5', '0.', '0.', '100.'], ['6', '0.', '0.', '200.'], ['7', '0.', '0.', '300.'], ['8', '0.', '0.', '400.'], ['9', '0.', '0.', '500.'], ['10', '0.', '0.', '600.'], ['11', '0.', '0.', '700.'], ['12', '0.', '0.', '800.'], ['13', '0.', '0.', '900.'], ['14', '0.', '0.', '1000.'], ['15', '0.', '0.', '1100.'], ['16', '0.', '0.', '1200.'], ['17', '0.', '0.', '1300.'], ['18', '0.', '0.', '1400.'], ['19', '0.', '0.', '1500.'], ['20', '0.', '0.', '1600.'], ['21', '0.', '0.', '1700.'], ['22', '0.', '0.', '1800.'], ['23', '0.', '0.', '1900.'], ['24', '0.', '0.', '2000.'], ['25', '0.', '0.', '2100.'], ['26', '0.', '0.', '2200.'], ['27', '0.', '0.', '2300.'], ['28', '0.', '0.', '2400.'], ['29', '0.', '0.', '2500.'], ['30', '0.', '0.', '2600.'], ['31', '0.', '0.', '2700.'], ['32', '0.', '0.', '2800.'], ['33', '0.', '0.', '2900.'], ['34', '0.', '0.', '3000.'], ['35', '0.', '0.', '3100.'], ['36', '0.', '0.', '3200.'], ['37', '0.', '0.', '3300.'], ['38', '0.', '0.', '3400.'], ['39', '0.', '0.', '3500.'], ['40', '0.', '0.', '3600.'], ['41', '0.', '0.', '3700.'], ['42', '0.', '0.', '3800.'], ['43', '0.', '0.', '3900.'], ['44', '0.', '1000.', '-100.'], ['45', '0.', '1000.', '0.'], ['46', '0.', '1000.', '4000.'], ['47', '0.', '1000.', '4100.'], ['48', '0.', '1000.', '100.'], ['49', '0.', '1000.', '200.'], ['50', '0.', '1000.', '300.'], ['51', '0.', '1000.', '400.'], ['52', '0.', '1000.', '500.'], ['53', '0.', '1000.', '600.'], ['54', '0.', '1000.', '700.'], ['55', '0.', '1000.', '800.'], ['56', '0.', '1000.', '900.'], ['57', '0.', '1000.', '1000.'], ['58', '0.', '1000.', '1100.'], ['59', '0.', '1000.', '1200.'], ['60', '0.', '1000.', '1300.'], ['61', '0.', '1000.', '1400.'], ['62', '0.', '1000.', '1500.'], ['63', '0.', '1000.', '1600.'], ['64', '0.', '1000.', '1700.'], ['65', '0.', '1000.', '1800.'], ['66', '0.', '1000.', '1900.'], ['67', '0.', '1000.', '2000.'], ['68', '0.', '1000.', '2100.'], ['69', '0.', '1000.', '2200.'], ['70', '0.', '1000.', '2300.'], ['71', '0.', '1000.', '2400.'], ['72', '0.', '1000.', '2500.'], ['73', '0.', '1000.', '2600.'], ['74', '0.', '1000.', '2700.'], ['75', '0.', '1000.', '2800.'], ['76', '0.', '1000.', '2900.'], ['77', '0.', '1000.', '3000.'], ['78', '0.', '1000.', '3100.'], ['79', '0.', '1000.', '3200.'], ['80', '0.', '1000.', '3300.'], ['81', '0.', '1000.', '3400.'], ['82', '0.', '1000.', '3500.'], ['83', '0.', '1000.', '3600.'], ['84', '0.', '1000.', '3700.'], ['85', '0.', '1000.', '3800.'], ['86', '0.', '1000.', '3900.'], ['87', '1000.', '0.', '-100.'], ['88', '1000.', '0.', '0.'], ['89', '1000.', '0.', '4000.'], ['90', '1000.', '0.', '4100.'], ['91', '1000.', '0.', '100.'], ['92', '1000.', '0.', '200.'], ['93', '1000.', '0.', '300.'], ['94', '1000.', '0.', '400.'], ['95', '1000.', '0.', '500.'], ['96', '1000.', '0.', '600.'], ['97', '1000.', '0.', '700.'], ['98', '1000.', '0.', '800.'], ['99', '1000.', '0.', '900.'], ['100', '1000.', '0.', '1000.'], ['101', '1000.', '0.', '1100.'], ['102', '1000.', '0.', '1200.'], ['103', '1000.', '0.', '1300.'], ['104', '1000.', '0.', '1400.'], ['105', '1000.', '0.', '1500.'], ['106', '1000.', '0.', '1600.'], ['107', '1000.', '0.', '1700.'], ['108', '1000.', '0.', '1800.'], ['109', '1000.', '0.', '1900.'], ['110', '1000.', '0.', '2000.'], ['111', '1000.', '0.', '2100.'], ['112', '1000.', '0.', '2200.'], ['113', '1000.', '0.', '2300.'], ['114', '1000.', '0.', '2400.'], ['115', '1000.', '0.', '2500.'], ['116', '1000.', '0.', '2600.'], ['117', '1000.', '0.', '2700.'], ['118', '1000.', '0.', '2800.'], ['119', '1000.', '0.', '2900.'], ['120', '1000.', '0.', '3000.'], ['121', '1000.', '0.', '3100.'], ['122', '1000.', '0.', '3200.'], ['123', '1000.', '0.', '3300.'], ['124', '1000.', '0.', '3400.'], ['125', '1000.', '0.', '3500.'], ['126', '1000.', '0.', '3600.'], ['127', '1000.', '0.', '3700.'], ['128', '1000.', '0.', '3800.'], ['129', '1000.', '0.', '3900.'], ['130', '1000.', '1000.', '-100.'], ['131', '1000.', '1000.', '0.'], ['132', '1000.', '1000.', '4000.'], ['133', '1000.', '1000.', '4100.'], ['134', '1000.', '1000.', '100.'], ['135', '1000.', '1000.', '200.'], ['136', '1000.', '1000.', '300.'], ['137', '1000.', '1000.', '400.'], ['138', '1000.', '1000.', '500.'], ['139', '1000.', '1000.', '600.'], ['140', '1000.', '1000.', '700.'], ['141', '1000.', '1000.', '800.'], ['142', '1000.', '1000.', '900.'], ['143', '1000.', '1000.', '1000.'], ['144', '1000.', '1000.', '1100.'], ['145', '1000.', '1000.', '1200.'], ['146', '1000.', '1000.', '1300.'], ['147', '1000.', '1000.', '1400.'], ['148', '1000.', '1000.', '1500.'], ['149', '1000.', '1000.', '1600.'], ['150', '1000.', '1000.', '1700.'], ['151', '1000.', '1000.', '1800.'], ['152', '1000.', '1000.', '1900.'], ['153', '1000.', '1000.', '2000.'], ['154', '1000.', '1000.', '2100.'], ['155', '1000.', '1000.', '2200.'], ['156', '1000.', '1000.', '2300.'], ['157', '1000.', '1000.', '2400.'], ['158', '1000.', '1000.', '2500.'], ['159', '1000.', '1000.', '2600.'], ['160', '1000.', '1000.', '2700.'], ['161', '1000.', '1000.', '2800.'], ['162', '1000.', '1000.', '2900.'], ['163', '1000.', '1000.', '3000.'], ['164', '1000.', '1000.', '3100.'], ['165', '1000.', '1000.', '3200.'], ['166', '1000.', '1000.', '3300.'], ['167', '1000.', '1000.', '3400.'], ['168', '1000.', '1000.', '3500.'], ['169', '1000.', '1000.', '3600.'], ['170', '1000.', '1000.', '3700.'], ['171', '1000.', '1000.', '3800.'], ['172', '1000.', '1000.', '3900.'], ['173', '0.', '0.', '0.'], ['174', '100.', '0.', '0.'], ['175', '200.', '0.', '0.'], ['176', '300.', '0.', '0.'], ['177', '400.', '0.', '0.'], ['178', '500.', '0.', '0.'], ['179', '600.', '0.', '0.'], ['180', '700.', '0.', '0.'], ['181', '800.', '0.', '0.'], ['182', '900.', '0.', '0.'], ['183', '1000.', '0.', '0.'], ['184', '0.', '1000.', '0.'], ['185', '100.', '1000.', '0.'], ['186', '200.', '1000.', '0.'], ['187', '300.', '1000.', '0.'], ['188', '400.', '1000.', '0.'], ['189', '500.', '1000.', '0.'], ['190', '600.', '1000.', '0.'], ['191', '700.', '1000.', '0.'], ['192', '800.', '1000.', '0.'], ['193', '900.', '1000.', '0.'], ['194', '1000.', '1000.', '0.'], ['195', '0.', '0.', '1000.'], ['196', '100.', '0.', '1000.'], ['197', '200.', '0.', '1000.'], ['198', '300.', '0.', '1000.'], ['199', '400.', '0.', '1000.'], ['200', '500.', '0.', '1000.'], ['201', '600.', '0.', '1000.'], ['202', '700.', '0.', '1000.'], ['203', '800.', '0.', '1000.'], ['204', '900.', '0.', '1000.'], ['205', '1000.', '0.', '1000.'], ['206', '0.', '1000.', '1000.'], ['207', '100.', '1000.', '1000.'], ['208', '200.', '1000.', '1000.'], ['209', '300.', '1000.', '1000.'], ['210', '400.', '1000.', '1000.'], ['211', '500.', '1000.', '1000.'], ['212', '600.', '1000.', '1000.'], ['213', '700.', '1000.', '1000.'], ['214', '800.', '1000.', '1000.'], ['215', '900.', '1000.', '1000.'], ['216', '1000.', '1000.', '1000.'], ['217', '0.', '0.', '2000.'], ['218', '100.', '0.', '2000.'], ['219', '200.', '0.', '2000.'], ['220', '300.', '0.', '2000.'], ['221', '400.', '0.', '2000.'], ['222', '500.', '0.', '2000.'], ['223', '600.', '0.', '2000.'], ['224', '700.', '0.', '2000.'], ['225', '800.', '0.', '2000.'], ['226', '900.', '0.', '2000.'], ['227', '1000.', '0.', '2000.'], ['228', '0.', '1000.', '2000.'], ['229', '100.', '1000.', '2000.'], ['230', '200.', '1000.', '2000.'], ['231', '300.', '1000.', '2000.'], ['232', '400.', '1000.', '2000.'], ['233', '500.', '1000.', '2000.'], ['234', '600.', '1000.', '2000.'], ['235', '700.', '1000.', '2000.'], ['236', '800.', '1000.', '2000.'], ['237', '900.', '1000.', '2000.'], ['238', '1000.', '1000.', '2000.'], ['239', '0.', '0.', '3000.'], ['240', '100.', '0.', '3000.'], ['241', '200.', '0.', '3000.'], ['242', '300.', '0.', '3000.'], ['243', '400.', '0.', '3000.'], ['244', '500.', '0.', '3000.'], ['245', '600.', '0.', '3000.'], ['246', '700.', '0.', '3000.'], ['247', '800.', '0.', '3000.'], ['248', '900.', '0.', '3000.'], ['249', '1000.', '0.', '3000.'], ['250', '0.', '1000.', '3000.'], ['251', '100.', '1000.', '3000.'], ['252', '200.', '1000.', '3000.'], ['253', '300.', '1000.', '3000.'], ['254', '400.', '1000.', '3000.'], ['255', '500.', '1000.', '3000.'], ['256', '600.', '1000.', '3000.'], ['257', '700.', '1000.', '3000.'], ['258', '800.', '1000.', '3000.'], ['259', '900.', '1000.', '3000.'], ['260', '1000.', '1000.', '3000.'], ['261', '0.', '0.', '4000.'], ['262', '100.', '0.', '4000.'], ['263', '200.', '0.', '4000.'], ['264', '300.', '0.', '4000.'], ['265', '400.', '0.', '4000.'], ['266', '500.', '0.', '4000.'], ['267', '600.', '0.', '4000.'], ['268', '700.', '0.', '4000.'], ['269', '800.', '0.', '4000.'], ['270', '900.', '0.', '4000.'], ['271', '1000.', '0.', '4000.'], ['272', '0.', '1000.', '4000.'], ['273', '100.', '1000.', '4000.'], ['274', '200.', '1000.', '4000.'], ['275', '300.', '1000.', '4000.'], ['276', '400.', '1000.', '4000.'], ['277', '500.', '1000.', '4000.'], ['278', '600.', '1000.', '4000.'], ['279', '700.', '1000.', '4000.'], ['280', '800.', '1000.', '4000.'], ['281', '900.', '1000.', '4000.'], ['282', '1000.', '1000.', '4000.'], ['283', '0.', '0.', '0.'], ['284', '0.', '100.', '0.'], ['285', '0.', '200.', '0.'], ['286', '0.', '300.', '0.'], ['287', '0.', '400.', '0.'], ['288', '0.', '500.', '0.'], ['289', '0.', '600.', '0.'], ['290', '0.', '700.', '0.'], ['291', '0.', '800.', '0.'], ['292', '0.', '900.', '0.'], ['293', '0.', '1000.', '0.'], ['294', '1000.', '0.', '0.'], ['295', '1000.', '100.', '0.'], ['296', '1000.', '200.', '0.'], ['297', '1000.', '300.', '0.'], ['298', '1000.', '400.', '0.'], ['299', '1000.', '500.', '0.'], ['300', '1000.', '600.', '0.'], ['301', '1000.', '700.', '0.'], ['302', '1000.', '800.', '0.'], ['303', '1000.', '900.', '0.'], ['304', '1000.', '1000.', '0.'], ['305', '0.', '0.', '1000.'], ['306', '0.', '100.', '1000.'], ['307', '0.', '200.', '1000.'], ['308', '0.', '300.', '1000.'], ['309', '0.', '400.', '1000.'], ['310', '0.', '500.', '1000.'], ['311', '0.', '600.', '1000.'], ['312', '0.', '700.', '1000.'], ['313', '0.', '800.', '1000.'], ['314', '0.', '900.', '1000.'], ['315', '0.', '1000.', '1000.'], ['316', '1000.', '0.', '1000.'], ['317', '1000.', '100.', '1000.'], ['318', '1000.', '200.', '1000.'], ['319', '1000.', '300.', '1000.'], ['320', '1000.', '400.', '1000.'], ['321', '1000.', '500.', '1000.'], ['322', '1000.', '600.', '1000.'], ['323', '1000.', '700.', '1000.'], ['324', '1000.', '800.', '1000.'], ['325', '1000.', '900.', '1000.'], ['326', '1000.', '1000.', '1000.'], ['327', '0.', '0.', '2000.'], ['328', '0.', '100.', '2000.'], ['329', '0.', '200.', '2000.'], ['330', '0.', '300.', '2000.'], ['331', '0.', '400.', '2000.'], ['332', '0.', '500.', '2000.'], ['333', '0.', '600.', '2000.'], ['334', '0.', '700.', '2000.'], ['335', '0.', '800.', '2000.'], ['336', '0.', '900.', '2000.'], ['337', '0.', '1000.', '2000.'], ['338', '1000.', '0.', '2000.'], ['339', '1000.', '100.', '2000.'], ['340', '1000.', '200.', '2000.'], ['341', '1000.', '300.', '2000.'], ['342', '1000.', '400.', '2000.'], ['343', '1000.', '500.', '2000.'], ['344', '1000.', '600.', '2000.'], ['345', '1000.', '700.', '2000.'], ['346', '1000.', '800.', '2000.'], ['347', '1000.', '900.', '2000.'], ['348', '1000.', '1000.', '2000.'], ['349', '0.', '0.', '3000.'], ['350', '0.', '100.', '3000.'], ['351', '0.', '200.', '3000.'], ['352', '0.', '300.', '3000.'], ['353', '0.', '400.', '3000.'], ['354', '0.', '500.', '3000.'], ['355', '0.', '600.', '3000.'], ['356', '0.', '700.', '3000.'], ['357', '0.', '800.', '3000.'], ['358', '0.', '900.', '3000.'], ['359', '0.', '1000.', '3000.'], ['360', '1000.', '0.', '3000.'], ['361', '1000.', '100.', '3000.'], ['362', '1000.', '200.', '3000.'], ['363', '1000.', '300.', '3000.'], ['364', '1000.', '400.', '3000.'], ['365', '1000.', '500.', '3000.'], ['366', '1000.', '600.', '3000.'], ['367', '1000.', '700.', '3000.'], ['368', '1000.', '800.', '3000.'], ['369', '1000.', '900.', '3000.'], ['370', '1000.', '1000.', '3000.'], ['371', '0.', '0.', '4000.'], ['372', '0.', '100.', '4000.'], ['373', '0.', '200.', '4000.'], ['374', '0.', '300.', '4000.'], ['375', '0.', '400.', '4000.'], ['376', '0.', '500.', '4000.'], ['377', '0.', '600.', '4000.'], ['378', '0.', '700.', '4000.'], ['379', '0.', '800.', '4000.'], ['380', '0.', '900.', '4000.'], ['381', '0.', '1000.', '4000.'], ['382', '1000.', '0.', '4000.'], ['383', '1000.', '100.', '4000.'], ['384', '1000.', '200.', '4000.'], ['385', '1000.', '300.', '4000.'], ['386', '1000.', '400.', '4000.'], ['387', '1000.', '500.', '4000.'], ['388', '1000.', '600.', '4000.'], ['389', '1000.', '700.', '4000.'], ['390', '1000.', '800.', '4000.'], ['391', '1000.', '900.', '4000.'], ['392', '1000.', '1000.', '4000.'], ['393', '-1000.', '0.', '-100.'], ['394', '-1000.', '0.', '0.'], ['395', '-1000.', '0.', '4000.'], ['396', '-1000.', '0.', '4100.'], ['397', '-1000.', '0.', '100.'], ['398', '-1000.', '0.', '200.'], ['399', '-1000.', '0.', '300.'], ['400', '-1000.', '0.', '400.'], ['401', '-1000.', '0.', '500.'], ['402', '-1000.', '0.', '600.'], ['403', '-1000.', '0.', '700.'], ['404', '-1000.', '0.', '800.'], ['405', '-1000.', '0.', '900.'], ['406', '-1000.', '0.', '1000.'], ['407', '-1000.', '0.', '1100.'], ['408', '-1000.', '0.', '1200.'], ['409', '-1000.', '0.', '1300.'], ['410', '-1000.', '0.', '1400.'], ['411', '-1000.', '0.', '1500.'], ['412', '-1000.', '0.', '1600.'], ['413', '-1000.', '0.', '1700.'], ['414', '-1000.', '0.', '1800.'], ['415', '-1000.', '0.', '1900.'], ['416', '-1000.', '0.', '2000.'], ['417', '-1000.', '0.', '2100.'], ['418', '-1000.', '0.', '2200.'], ['419', '-1000.', '0.', '2300.'], ['420', '-1000.', '0.', '2400.'], ['421', '-1000.', '0.', '2500.'], ['422', '-1000.', '0.', '2600.'], ['423', '-1000.', '0.', '2700.'], ['424', '-1000.', '0.', '2800.'], ['425', '-1000.', '0.', '2900.'], ['426', '-1000.', '0.', '3000.'], ['427', '-1000.', '0.', '3100.'], ['428', '-1000.', '0.', '3200.'], ['429', '-1000.', '0.', '3300.'], ['430', '-1000.', '0.', '3400.'], ['431', '-1000.', '0.', '3500.'], ['432', '-1000.', '0.', '3600.'], ['433', '-1000.', '0.', '3700.'], ['434', '-1000.', '0.', '3800.'], ['435', '-1000.', '0.', '3900.'], ['436', '-1000.', '0.', '0.'], ['437', '-900.', '0.', '0.'], ['438', '-800.', '0.', '0.'], ['439', '-700.', '0.', '0.'], ['440', '-600.', '0.', '0.'], ['441', '-500.', '0.', '0.'], ['442', '-400.', '0.', '0.'], ['443', '-300.', '0.', '0.'], ['444', '-200.', '0.', '0.'], ['445', '-100.', '0.', '0.'], ['446', '0.', '0.', '0.'], ['447', '-1000.', '1000.', '0.'], ['448', '-900.', '1000.', '0.'], ['449', '-800.', '1000.', '0.'], ['450', '-700.', '1000.', '0.'], ['451', '-600.', '1000.', '0.'], ['452', '-500.', '1000.', '0.'], ['453', '-400.', '1000.', '0.'], ['454', '-300.', '1000.', '0.'], ['455', '-200.', '1000.', '0.'], ['456', '-100.', '1000.', '0.'], ['457', '0.', '1000.', '0.'], ['458', '-1000.', '1000.', '1000.'], ['459', '-900.', '1000.', '1000.'], ['460', '-800.', '1000.', '1000.'], ['461', '-700.', '1000.', '1000.'], ['462', '-600.', '1000.', '1000.'], ['463', '-500.', '1000.', '1000.'], ['464', '-400.', '1000.', '1000.'], ['465', '-300.', '1000.', '1000.'], ['466', '-200.', '1000.', '1000.'], ['467', '-100.', '1000.', '1000.'], ['468', '0.', '1000.', '1000.'], ['469', '-1000.', '1000.', '2000.'], ['470', '-900.', '1000.', '2000.'], ['471', '-800.', '1000.', '2000.'], ['472', '-700.', '1000.', '2000.'], ['473', '-600.', '1000.', '2000.'], ['474', '-500.', '1000.', '2000.'], ['475', '-400.', '1000.', '2000.'], ['476', '-300.', '1000.', '2000.'], ['477', '-200.', '1000.', '2000.'], ['478', '-100.', '1000.', '2000.'], ['479', '0.', '1000.', '2000.'], ['480', '-1000.', '1000.', '3000.'], ['481', '-900.', '1000.', '3000.'], ['482', '-800.', '1000.', '3000.'], ['483', '-700.', '1000.', '3000.'], ['484', '-600.', '1000.', '3000.'], ['485', '-500.', '1000.', '3000.'], ['486', '-400.', '1000.', '3000.'], ['487', '-300.', '1000.', '3000.'], ['488', '-200.', '1000.', '3000.'], ['489', '-100.', '1000.', '3000.'], ['490', '0.', '1000.', '3000.'], ['491', '-1000.', '0.', '0.'], ['492', '-1000.', '100.', '0.'], ['493', '-1000.', '200.', '0.'], ['494', '-1000.', '300.', '0.'], ['495', '-1000.', '400.', '0.'], ['496', '-1000.', '500.', '0.'], ['497', '-1000.', '600.', '0.'], ['498', '-1000.', '700.', '0.'], ['499', '-1000.', '800.', '0.'], ['500', '-1000.', '900.', '0.'], ['501', '-1000.', '1000.', '0.'], ['502', '-1000.', '1000.', '4000.'], ['503', '-900.', '1000.', '4000.'], ['504', '-800.', '1000.', '4000.'], ['505', '-700.', '1000.', '4000.'], ['506', '-600.', '1000.', '4000.'], ['507', '-500.', '1000.', '4000.'], ['508', '-400.', '1000.', '4000.'], ['509', '-300.', '1000.', '4000.'], ['510', '-200.', '1000.', '4000.'], ['511', '-100.', '1000.', '4000.'], ['512', '0.', '1000.', '4000.'], ['513', '-1000.', '0.', '1000.'], ['514', '-900.', '0.', '1000.'], ['515', '-800.', '0.', '1000.'], ['516', '-700.', '0.', '1000.'], ['517', '-600.', '0.', '1000.'], ['518', '-500.', '0.', '1000.'], ['519', '-400.', '0.', '1000.'], ['520', '-300.', '0.', '1000.'], ['521', '-200.', '0.', '1000.'], ['522', '-100.', '0.', '1000.'], ['523', '0.', '0.', '1000.'], ['524', '-1000.', '0.', '2000.'], ['525', '-900.', '0.', '2000.'], ['526', '-800.', '0.', '2000.'], ['527', '-700.', '0.', '2000.'], ['528', '-600.', '0.', '2000.'], ['529', '-500.', '0.', '2000.'], ['530', '-400.', '0.', '2000.'], ['531', '-300.', '0.', '2000.'], ['532', '-200.', '0.', '2000.'], ['533', '-100.', '0.', '2000.'], ['534', '0.', '0.', '2000.'], ['535', '-1000.', '0.', '3000.'], ['536', '-900.', '0.', '3000.'], ['537', '-800.', '0.', '3000.'], ['538', '-700.', '0.', '3000.'], ['539', '-600.', '0.', '3000.'], ['540', '-500.', '0.', '3000.'], ['541', '-400.', '0.', '3000.'], ['542', '-300.', '0.', '3000.'], ['543', '-200.', '0.', '3000.'], ['544', '-100.', '0.', '3000.'], ['545', '0.', '0.', '3000.'], ['546', '-1000.', '0.', '4000.'], ['547', '-900.', '0.', '4000.'], ['548', '-800.', '0.', '4000.'], ['549', '-700.', '0.', '4000.'], ['550', '-600.', '0.', '4000.'], ['551', '-500.', '0.', '4000.'], ['552', '-400.', '0.', '4000.'], ['553', '-300.', '0.', '4000.'], ['554', '-200.', '0.', '4000.'], ['555', '-100.', '0.', '4000.'], ['556', '0.', '0.', '4000.'], ['557', '-1000.', '0.', '1000.'], ['558', '-1000.', '100.', '1000.'], ['559', '-1000.', '200.', '1000.'], ['560', '-1000.', '300.', '1000.'], ['561', '-1000.', '400.', '1000.'], ['562', '-1000.', '500.', '1000.'], ['563', '-1000.', '600.', '1000.'], ['564', '-1000.', '700.', '1000.'], ['565', '-1000.', '800.', '1000.'], ['566', '-1000.', '900.', '1000.'], ['567', '-1000.', '1000.', '1000.'], ['568', '-1000.', '0.', '3000.'], ['569', '-1000.', '100.', '3000.'], ['570', '-1000.', '200.', '3000.'], ['571', '-1000.', '300.', '3000.'], ['572', '-1000.', '400.', '3000.'], ['573', '-1000.', '500.', '3000.'], ['574', '-1000.', '600.', '3000.'], ['575', '-1000.', '700.', '3000.'], ['576', '-1000.', '800.', '3000.'], ['577', '-1000.', '900.', '3000.'], ['578', '-1000.', '1000.', '3000.'], ['579', '-1000.', '0.', '2000.'], ['580', '-1000.', '100.', '2000.'], ['581', '-1000.', '200.', '2000.'], ['582', '-1000.', '300.', '2000.'], ['583', '-1000.', '400.', '2000.'], ['584', '-1000.', '500.', '2000.'], ['585', '-1000.', '600.', '2000.'], ['586', '-1000.', '700.', '2000.'], ['587', '-1000.', '800.', '2000.'], ['588', '-1000.', '900.', '2000.'], ['589', '-1000.', '1000.', '2000.'], ['590', '-1000.', '0.', '4000.'], ['591', '-1000.', '100.', '4000.'], ['592', '-1000.', '200.', '4000.'], ['593', '-1000.', '300.', '4000.'], ['594', '-1000.', '400.', '4000.'], ['595', '-1000.', '500.', '4000.'], ['596', '-1000.', '600.', '4000.'], ['597', '-1000.', '700.', '4000.'], ['598', '-1000.', '800.', '4000.'], ['599', '-1000.', '900.', '4000.'], ['600', '-1000.', '1000.', '4000.'], ['601', '-1000.', '1000.', '-100.'], ['602', '-1000.', '1000.', '0.'], ['603', '-1000.', '1000.', '4000.'], ['604', '-1000.', '1000.', '4100.'], ['605', '-1000.', '1000.', '100.'], ['606', '-1000.', '1000.', '200.'], ['607', '-1000.', '1000.', '300.'], ['608', '-1000.', '1000.', '400.'], ['609', '-1000.', '1000.', '500.'], ['610', '-1000.', '1000.', '600.'], ['611', '-1000.', '1000.', '700.'], ['612', '-1000.', '1000.', '800.'], ['613', '-1000.', '1000.', '900.'], ['614', '-1000.', '1000.', '1000.'], ['615', '-1000.', '1000.', '1100.'], ['616', '-1000.', '1000.', '1200.'], ['617', '-1000.', '1000.', '1300.'], ['618', '-1000.', '1000.', '1400.'], ['619', '-1000.', '1000.', '1500.'], ['620', '-1000.', '1000.', '1600.'], ['621', '-1000.', '1000.', '1700.'], ['622', '-1000.', '1000.', '1800.'], ['623', '-1000.', '1000.', '1900.']] 
dic1=defaultdict(list) 

for id,x,y,z in data1: 
    dic1[(x,y)].append((id,z)) 

#sort 
for key in dic1: 
    dic1[key].sort(key=lambda x:float(x[1])) 

for i,row in enumerate(data2): 
    id,x,y,z=row 
    z_levels=[item[1] for item in dic1[(x,y)]] 
    for k,l in zip(z_levels,z_levels[1:]): 
     if k<=z<=l: 
      #do something here 
      #data2[i][1]=None #change x co-ordinate 
      #data2[i][2]=None #change y co-ordinate 
      break 
+0

謝謝!你的代碼也適用於第一部分:爲每個'(X,Y)'對查找和排序不同的'Z'級別。但是現在我需要處理結果,以便根據'DataCoord2'每一行的'(x,y,z)'座標來改變'DataCoord2'列表的X和Y座標,並且每個'(X ,Y)'對並關聯和排序'Z級別'。 – jpcgandre 2013-04-26 10:31:41

+1

@jpcgandre請在問題主體中發佈一些示例輸入輸出,因爲它很難理解您在尋找什麼。 – 2013-04-26 10:38:04

+0

我已添加其他信息。希望它有幫助 – jpcgandre 2013-04-26 10:55:56

1

這是你想要的嗎? 我已經使用只是簡單的字典..和,所使用的元組作爲重點

result={} 
for x in DataCoord: 
    result.setdefault((x[1],x[2]),{}) 
    result[(x[1],x[2])][tuple(x)]=x[0] 

輸出:

{('-1000.', '0.'): 
    {('436', '-1000.', '0.', '0.'): '436', 
    ('491', '-1000.', '0.', '0.'): '491', 
    ('513', '-1000.', '0.', '1000.'): '513', 
    ('524', '-1000.', '0.', '2000.'): '524', 
    ('535', '-1000.', '0.', '3000.'): '535', 
. 
. 
. 

('-1000.', '2000.'): 
    {('818', '-1000.', '2000.', '0.'): '818', 
    ('863', '-1000.', '2000.', '0.'): '863', 
    ('874', '-1000.', '2000.', '1000.'): '874', 
    ('885', '-1000.', '2000.', '2000.'): '885', 
.. 
+0

謝謝。它很近。我該如何處理你的'result'來根據'Z'和每個'Z level'之間的相對位置爲每個'(X,Y)'對改變'X'和'Y'座標'DataCoord'我在每個「Z」級之間有'Z'座標)? – jpcgandre 2013-04-26 09:44:33

+0

@jpcgandre:你能解釋一下嗎?或者只是在你的文章中添加關於該內容的修改。 – namit 2013-04-26 09:50:27

+0

之後是'識別和排序這個(x,y)對的不同zlevels之後我想要做的:'line。 – jpcgandre 2013-04-26 09:52:37

相關問題