Boolean Masks for Selection
Filtering values with conditions.
Compare a Whole Array
Write a comparison and NumPy applies it to every element at once. The result is a boolean array of True and False values.
a = np.array([5, 12, 7, 20])
a > 10 # [False True False True]That Result Is a Mask
This array of True and False is a mask. Each position marks whether that element passed your condition.
All lessons in this course
- Reshape and Flatten Arrays
- Sum, Mean, and the Axis Trick
- Boolean Masks for Selection
- Random Numbers and Seeds