What is the fastest way to map group names of numpy array to indices?

前端 未结 3 380
不思量自难忘°
不思量自难忘° 2020-12-17 20:48

I\'m working with 3D pointcloud of Lidar. The points are given by numpy array that looks like this:

points = np.array([[61651921, 416326074, 39805], [6160525         


        
3条回答
  •  感动是毒
    2020-12-17 21:09

    You might just iterate and add the index of each element to the corresponding list.

    from collections import defaultdict
    
    res = defaultdict(list)
    
    for idx, elem in enumerate(cubes):
        #res[tuple(elem)].append(idx)
        res[elem.tobytes()].append(idx)
    

    Runtime can be further improved by using tobytes() instead of converting the key to a tuple.

提交回复
热议问题