循环添加[key,value]到python字典

时间:2018-08-20 15:35:06

标签: python dictionary point-clouds

我是python的新手,我试图通过将一堆pcd文件(每个文件本质上是一个n * 3数组)建立索引,以使其与它们的类类型匹配。某些文件是1、2、3等。我尝试运行它时遇到unhashable numpy.ndarray错误。由于我有一排文件需要加载和建立索引,应该如何进行?

path= glob.glob("path/to/pcd/folder/*.pcd")
data_dict=dict()
for i in range(len(list(path):
    currentPath = path[i]
    classtype=currentPath[-5:]
    classtype=classtype[0]
    p = pcl.load(path[i])
    a = np.asarray(p)
    data_dict[a]=classtype
    
    

1 个答案:

答案 0 :(得分:1)

要将所有PCL放入字典中以便查找其对应的Classtype,您需要执行以下操作:

my_dict = dict() # declaring empty dictionary
for point_cloud in pcl_list:
    my_dict[point_cloud] = classtype #somewhere in the loop you need to set what classtype is for each specific point_cloud

现在您可以执行以下操作:

>> my_dict[some_pcl]
<the corresponding classtype>