Loading...
Use boolean conditions to filter NumPy arrays.
Boolean indexing selects elements based on conditions:
arr[arr > 5] # All elements greater than 5
arr[arr % 2 == 0] # All even elements
Write a function filter_array(arr, threshold) that returns a dictionary with:
arr = [1, 5, 3, 8, 2, 9, 4, 7], threshold = 5
{'above': [8, 9, 7], 'below_eq': [1, 5, 3, 2, 4], 'count_above': 3}arr[arr > 5] gives [8, 9, 7], arr[arr <= 5] gives [1, 5, 3, 2, 4]