How to filter numpy array by list of indices?

后端 未结 4 1074
清歌不尽
清歌不尽 2020-12-06 09:42

I have a numpy array, filtered__rows, comprised of LAS data [x, y, z, intensity, classification]. I have created a cKDTree of points

4条回答
  •  盖世英雄少女心
    2020-12-06 10:15

    numpy.take can be useful and works well for multimensional arrays.

    import numpy as np
    
    filter_indices = [1, 2]
    axis = 0
    array = np.array([[1, 2, 3, 4, 5], 
                      [10, 20, 30, 40, 50], 
                      [100, 200, 300, 400, 500]])
    
    print(np.take(array, filter_indices, axis))
    # [[ 10  20  30  40  50]
    #  [100 200 300 400 500]]
    
    axis = 1
    print(np.take(array, filter_indices, axis))
    # [[  2   3]
    #  [ 20  30]
    # [200 300]]
    

提交回复
热议问题