0 / 34
Lesson 17

Where & Select

np.where(cond, if_true, if_false):

np.where(a > 0, a, 0)  # keep positives
Why this matters

np.where is vectorized if/else: clip values, impute sentinels, or build masks into new arrays without Python branches on each element.

Often paired with boolean indexing; use where when you need both branches materialized.

ResourcesDocs, references & more โ€” opens in a new tab
๐ŸŽฏ Your Task

grades = [92,45,78,55,88,62,95,40]. Keep โ‰ฅ60, replace rest with 0 โ†’ result.

np.where(grades >= 60, grades, 0)
exercise.py
โŒ˜โŽ run ยท โŒ˜โ† โ†’ nav
โ–ถ Output
Run your code to see output here.