Python practice: Array Filtering & Conditional Logic (np.where & np.select)

Chapter 18 · 8 questions · included in full access

  1. Question 1 · easy

    Filter array with boolean mask

    Given orders = np.array([45, 120, 85, 230, 15, 310]), filter orders >= 100 with orders[orders >= 100] and print high_vol:

    Solve it in your browser
  2. Question 2 · easy

    Count matching conditions with np.sum

    Given scores = np.array([85, 92, 78, 65, 95]), count how many are >= 80 using np.sum(scores >= 80) and print the count:

    Solve it in your browser
  3. Question 3 · easy

    Vectorized IF with np.where

    Given balances = np.array([1500, -200, 3400, -50]), use np.where(balances >= 0, "Solvent", "Overdrawn") to classify accounts. Print status:

    Solve it in your browser
  4. Question 4 · easy

    Cap negative balances at zero

    Given balances = np.array([1500, -200, 3400, -50]), cap negative balances at 0 using np.where(balances < 0, 0, balances). Print capped:

    Solve it in your browser
  5. Question 5 · medium

    Multi-tier classification with np.select

    Given sales = np.array([45000, 120000, 85000, 250000]), assign tiers with np.select([sales >= 200000, sales >= 100000, sales >= 50000], ["Platinum", "Gold", "Silver"], default="Bronze"). Print tiers:

    Solve it in your browser
  6. Question 6 · medium

    Multi-criteria boolean filtering with bitwise &

    Given units = np.array([12, 25, 8, 30]) and prices = np.array([150, 220, 350, 180]), find units where (units >= 20) & (prices >= 200) and print matching units:

    Solve it in your browser
  7. Question 7 · easy

    Binary High / Low tagging with np.where

    Given margins = np.array([0.15, 0.28, 0.32, 0.12]), tag as "High" if margins >= 0.25, else "Standard". Print tags:

    Solve it in your browser
  8. Question 8 · easy

    Benchmark np.select vs loop logic

    Given scores = np.array([45, 75, 90]), categorize with np.select([scores >= 80, scores >= 60], ["Pass", "Retest"], default="Fail"). Print results:

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing