How to filter numpy array by list of indices?

Barbarossa picture Barbarossa · Nov 6, 2013 · Viewed 51k times · Source

I have a numpy array, filtered__rows, comprised of LAS data [x, y, z, intensity, classification]. I have created a cKDTree of points and have found nearest neighbors, query_ball_point, which is a list of indices for the point and its neighbors.

Is there a way to filter filtered__rows to create an array of only points whose index is in the list returned by query_ball_point?

Answer

Joran Beasley picture Joran Beasley · Nov 6, 2013

It looks like you just need a basic integer array indexing:

filter_indices = [1,3,5]
np.array([11,13,155,22,0xff,32,56,88])[filter_indices]