简体   繁体   English

FInd(X,Y)对和关联的Z坐标

[英]FInd (X, Y) pairs and associated Z coordinates

I have a list of lists DataCoord : 我有一个列表列表DataCoord

[nodeID, X, Y, Z]

with multiple rows. 多行。 Some nodes will have the same X and Y coordinates and different Z coordinate. 一些节点将具有相同的XY坐标以及不同的Z坐标。 For example, say I have: 例如,说我有:

Pair (X,Y) = (0,0):
[1, 0, 0, 0,]: level 0
[m, 0, 0, 200]: level m
[n, 0, 0, 100]: level n #the DataCoord list may not be ordered

I'd like to identify and sort the different z levels for this (x,y) pair. 我想识别并排序此(x,y)对的不同z等级。
And the same for other parts which share the same X and Y coordinates. 对于共享相同XY坐标的其他部分也是如此。

Any help is appreciated. 任何帮助表示赞赏。

EDIT: as an example of DataCoord : 编辑:作为DataCoord的示例:

[['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.']]

Loop over your values and collect the Z coordinates per X, Y pair; 遍历您的值并收集每个X,Y对的Z坐标; using collections.defaultdict makes this a little easier, setting the default to an empty set for each key: 使用collections.defaultdict可以使此操作变得简单一些,将每个键的默认值set为空set

from collections import defaultdict

levels = defaultdict(set)

for node_id, x, y, z in list_of_datacoords:
    levels[x, y].add(z)

Now levels is a dictionary mapping x, y coordinates to a set of unique z values. 现在, levels是一个将x, y坐标映射到一组唯一z值的字典。

For your example input, that results in: 对于您的示例输入,结果为:

>>> pprint(dict(levels))
{('-1000.', '0.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('-1000.', '1000.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('-1000.', '2000.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('0.', '0.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('0.', '1000.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('0.', '2000.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('1000.', '0.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('1000.', '1000.'): set(['0.', '1000.', '2000.', '3000.', '4000.']),
 ('1000.', '2000.'): set(['0.', '1000.', '2000.', '3000.', '4000.'])}

You can now get a sorted list of levels per x, y pair: 现在,您可以获得每个x, y对的级别的排序列表:

for (x, y), z in levels.iteritems():
    z = sorted(z)
    # now you have x, y and a sorted list of `z` values.

The pprint() call above already printed the sets in sorted order; 上面的pprint()调用已经按排序顺序打印了集合; that is because pprint() sorts the output of python sequences by default. 这是因为pprint()默认情况下对python序列的输出进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用(X,Y),(X,Z)和(Y,Z)对以及相关的X,Y或Z坐标进行映射和处理 - Map and work with (X, Y), (X,Z) and (Y,Z) pairs and associated X, Y or Z coordinates 查找给定z坐标值的相应[x,y]坐标 - Find the corresponding [x,y] coordinates for a given z coordinate value 将边界框坐标转换为 x,y 对 - convert bounding box coordinates to x,y pairs 在框中随机化(x,y,z)坐标 - Randomizing (x,y,z) coordinates within a box 在Ruby / Python中可视化x,y,z坐标? - Visualizing x,y,z coordinates in Ruby/Python? 从 x,y 坐标查找最近的 x,y,z 点 - Finding closest x,y,z points from x,y coordinates 将(x,y)坐标转换为(x,y,z)以移动机器人手臂 - Translation of (x, y) coordinates into (x, y, z) for move robot arm 如何制作 3D plot(X,Y,Z),将 Z 值分配给 X,Y 有序对? - How to make a 3D plot (X, Y, Z), assigning Z values to X,Y ordered pairs? 作法:给定[U,x,y,z]的值(x,y,z)输出U的相关值 - How to: Given a value (x,y,z) from an arry [U,x,y,z] output associated value of U 给定一组在(X,Y,Z)坐标中定义的点,在任意(X,Y)处插值Z值 - Given a set of points defined in (X, Y, Z) coordinates, interpolate Z-value at arbitrary (X, Y)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM