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)
โโ run ยท โโ โ nav
โถ Output
Run your code to see output here.