0 / 34

Invite others

Progress

0 / 34

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.