In NumPy, filtering refers to the process of selecting elements from an array that satisfy certain conditions. NumPy provides several methods for filtering arrays:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
# Create a boolean mask based on a condition
mask = arr > 2
# Use the mask to filter the array
filtered_arr = arr[mask]
print(filtered_arr)
[3 4 5]