0
0
NumPydata~15 mins

Boolean type in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Boolean Type with NumPy Arrays
📖 Scenario: You are working with a small dataset of temperatures recorded over a week. You want to find out which days were warmer than 20 degrees Celsius.
🎯 Goal: Create a NumPy array of temperatures, set a threshold temperature, create a Boolean array showing which days are warmer than the threshold, and print the Boolean array.
📋 What You'll Learn
Create a NumPy array called temperatures with the exact values: 18, 22, 19, 24, 20, 21, 17
Create a variable called threshold and set it to 20
Create a Boolean NumPy array called warm_days that is True where temperatures is greater than threshold
Print the warm_days array
💡 Why This Matters
🌍 Real World
Checking temperature data to find days warmer than a certain value is common in weather analysis and climate studies.
💼 Career
Data scientists often use Boolean arrays to filter data quickly and make decisions based on conditions.
Progress0 / 4 steps
1
Create the temperatures array
Create a NumPy array called temperatures with these exact values: 18, 22, 19, 24, 20, 21, 17
NumPy
Need a hint?

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

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

Just assign the number 20 to the variable threshold.

3
Create the Boolean array for warm days
Create a Boolean NumPy array called warm_days that is True where temperatures is greater than threshold using the expression temperatures > threshold
NumPy
Need a hint?

Use the comparison operator > between temperatures and threshold to get a Boolean array.

4
Print the Boolean array
Print the warm_days array using print(warm_days)
NumPy
Need a hint?

Use print(warm_days) to display the Boolean array.