0PricingLogin
Data Science Academy · Lesson

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

  1. Reshape and Flatten Arrays
  2. Sum, Mean, and the Axis Trick
  3. Boolean Masks for Selection
  4. Random Numbers and Seeds
← Back to Data Science Academy