0
0
NumPydata~15 mins

Creating boolean arrays in NumPy - Try It Yourself

Choose your learning style9 modes available
Creating boolean arrays
📖 Scenario: Imagine you have a list of temperatures recorded every day for a week. You want to find out which days were warmer than 20 degrees Celsius.
🎯 Goal: You will create a boolean array that shows True for days warmer than 20 degrees and False otherwise.
📋 What You'll Learn
Use numpy to create arrays
Create a numpy array with exact temperature values
Create a boolean array using a condition
Print the boolean array as output
💡 Why This Matters
🌍 Real World
This technique helps in filtering data based on conditions, like finding days warmer than a certain temperature.
💼 Career
Data scientists often create boolean arrays to filter and analyze data quickly and efficiently.
Progress0 / 4 steps
1
Create the temperature 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 numbers.

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

Just assign the number 20 to a variable named threshold.

3
Create the boolean array
Create a boolean numpy array called warm_days that is True where temperatures are greater than threshold, and False otherwise.
NumPy
Need a hint?

Use the comparison operator > between the array and the threshold variable.

4
Print the boolean array
Print the warm_days array to see which days were warmer than 20 degrees.
NumPy
Need a hint?

Use print(warm_days) to display the boolean array.