Boolean masking, conditional filtering, and index array selection.
Boolean indexing lets you filter array elements using condition expressions like `arr > 25`. NumPy creates a boolean mask and extracts all elements where the condition is True.
A boolean mask is a stencil with holes cut out wherever your condition is True. Placing the stencil over the array lets only matching numbers pass through.
Expressions like `arr > 20` evaluate element-wise into an array of booleans `[False, True, ...]`. Passing this mask into `arr[mask]` filters elements.
filtered = arr[arr > 20]filtered = arr[arr > 10 and arr < 50] # Python 'and' fails on arraysfiltered = arr[(arr > 10) & (arr < 50)]Use bitwise `&` (AND) and `|` (OR) with parentheses for multiple conditions in NumPy.
Solve the objective below using NumPy vectorized syntax
Create `arr = np.array([10, 15, 20, 25, 30])`, filter all elements greater than 18 using `arr[arr > 18]`, and print.
[20 25 30]