0
0
NumPydata~15 mins

Counting with boolean arrays in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Counting with boolean arrays
📖 Scenario: You work in a store and have a list of daily sales numbers. You want to find out how many days had sales above a certain target.
🎯 Goal: Build a small program that counts how many days had sales greater than a target using boolean arrays in NumPy.
📋 What You'll Learn
Use NumPy to create and work with arrays
Create a boolean array by comparing sales to a target
Count the number of True values in the boolean array
💡 Why This Matters
🌍 Real World
Stores and businesses often want to quickly find how many days or items meet a sales goal to track performance.
💼 Career
Data analysts and scientists use boolean arrays and counting techniques to summarize and analyze data efficiently.
Progress0 / 4 steps
1
Create the sales data array
Import NumPy as np and create a NumPy array called sales with these exact daily sales values: 100, 150, 90, 200, 130.
NumPy
Need a hint?

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

2
Set the sales target
Create a variable called target and set it to the value 120.
NumPy
Need a hint?

Just assign the number 120 to the variable target.

3
Create a boolean array for sales above target
Create a boolean NumPy array called above_target by comparing sales to target using the greater than operator >.
NumPy
Need a hint?

Use sales > target to get a boolean array.

4
Count and print the number of days above target
Use np.sum() on the above_target array to count how many days had sales above the target. Print the result.
NumPy
Need a hint?

Use np.sum(above_target) to count True values, then print it.