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
?
To select an element from Numpy Array , we can use [] operator i.e. It will return the element at given index only.
In NumPy, you filter an array using a boolean index list. A boolean index list is a list of booleans corresponding to indexes in the array. If the value at an index is True that element is contained in the filtered array, if the value at that index is False that element is excluded from the filtered array.
If you want to extract elements that meet the condition, you can use ndarray[conditional expression] . Even if the original ndarray is a multidimensional array, a flattened one-dimensional array is returned. A new ndarray is returned, and the original ndarray is unchanged.
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]
numpy.take
can be useful and works well for multimensional arrays.
import numpy as np filter_indices = [1, 2] array = np.array([[1, 2, 3, 4, 5], [10, 20, 30, 40, 50], [100, 200, 300, 400, 500]]) axis = 0 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]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With