在循环中将 [key,value] 添加到 Python 字典中



我是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

若要将所有 PCL 放入字典中以便查找其相应的类类型,需要执行以下操作:

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>

最新更新