Python practice: Array Filtering & Conditional Logic (np.where & np.select)
Chapter 18 · 8 questions · included in full access
Question 1 · easy
Filter array with boolean mask
Solve it in your browserGiven
orders = np.array([45, 120, 85, 230, 15, 310]), filter orders >= 100 withorders[orders >= 100]and printhigh_vol:Question 2 · easy
Count matching conditions with np.sum
Solve it in your browserGiven
scores = np.array([85, 92, 78, 65, 95]), count how many are >= 80 usingnp.sum(scores >= 80)and print the count:Question 3 · easy
Vectorized IF with np.where
Solve it in your browserGiven
balances = np.array([1500, -200, 3400, -50]), usenp.where(balances >= 0, "Solvent", "Overdrawn")to classify accounts. Printstatus:Question 4 · easy
Cap negative balances at zero
Solve it in your browserGiven
balances = np.array([1500, -200, 3400, -50]), cap negative balances at 0 usingnp.where(balances < 0, 0, balances). Printcapped:Question 5 · medium
Multi-tier classification with np.select
Solve it in your browserGiven
sales = np.array([45000, 120000, 85000, 250000]), assign tiers withnp.select([sales >= 200000, sales >= 100000, sales >= 50000], ["Platinum", "Gold", "Silver"], default="Bronze"). Printtiers:Question 6 · medium
Multi-criteria boolean filtering with bitwise &
Solve it in your browserGiven
units = np.array([12, 25, 8, 30])andprices = np.array([150, 220, 350, 180]), find units where(units >= 20) & (prices >= 200)and print matching units:Question 7 · easy
Binary High / Low tagging with np.where
Solve it in your browserGiven
margins = np.array([0.15, 0.28, 0.32, 0.12]), tag as"High"ifmargins >= 0.25, else"Standard". Printtags:Question 8 · easy
Benchmark np.select vs loop logic
Solve it in your browserGiven
scores = np.array([45, 75, 90]), categorize withnp.select([scores >= 80, scores >= 60], ["Pass", "Retest"], default="Fail"). Printresults:
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing