0
0
NumPydata~15 mins

Boolean indexing in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Boolean Indexing with NumPy Arrays
📖 Scenario: You are working with a list of daily temperatures recorded over a week. You want to find which days were warmer than a certain temperature to plan outdoor activities.
🎯 Goal: Build a program that uses NumPy boolean indexing to select temperatures above a threshold.
📋 What You'll Learn
Create a NumPy array with exact temperature values
Create a threshold variable for temperature
Use boolean indexing to select temperatures above the threshold
Print the selected temperatures
💡 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 relevant data points for analysis and visualization.
Progress0 / 4 steps
1
Create the temperature data array
Import NumPy as np and create a NumPy array called temps with these exact values: 22, 19, 25, 20, 18, 24, 21.
NumPy
Need a hint?

Use np.array([...]) to create the array with the exact temperatures.

2
Set the temperature threshold
Create a variable called threshold and set it to the integer 20.
NumPy
Need a hint?

Just assign the number 20 to a variable named threshold.

3
Select temperatures above the threshold using boolean indexing
Create a variable called warm_days that uses boolean indexing on temps to select only the temperatures greater than threshold.
NumPy
Need a hint?

Use temps > threshold inside the brackets to filter the array.

4
Print the warm temperatures
Print the variable warm_days to display the temperatures above the threshold.
NumPy
Need a hint?

Use print(warm_days) to show the filtered temperatures.