Boolean indexing for filtering
📖 Scenario: Imagine you have a list of daily temperatures recorded in a city. You want to find out which days were warm, meaning the temperature was above 20 degrees Celsius.
🎯 Goal: You will create a NumPy array of temperatures, set a threshold for warm days, use boolean indexing to filter the warm days, and then display those warm temperatures.
📋 What You'll Learn
Create a NumPy array called
temperatures with the exact values: 15, 22, 19, 24, 18, 30, 21Create a variable called
warm_threshold and set it to 20Use boolean indexing with
temperatures and warm_threshold to create a new array called warm_days containing only temperatures above the thresholdPrint the
warm_days array💡 Why This Matters
🌍 Real World
Filtering data based on conditions is common in weather analysis, finance, and health monitoring to focus on important values.
💼 Career
Data scientists often use boolean indexing to quickly select and analyze subsets of data without loops, making their code faster and cleaner.
Progress0 / 4 steps