0
0
NumPydata~15 mins

np.where() for conditional selection in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Using np.where() for Conditional Selection
📖 Scenario: You work in a store that tracks daily sales numbers. You want to quickly find which days had sales above a certain target.
🎯 Goal: Build a small program that uses np.where() to find the days with sales above a target number.
📋 What You'll Learn
Create a numpy array with exact daily sales numbers
Create a variable for the sales target
Use np.where() to find indices where sales exceed the target
Print the indices of days with sales above the target
💡 Why This Matters
🌍 Real World
Stores and businesses often need to quickly find days or items that meet certain conditions, like sales targets, to make decisions.
💼 Career
Data analysts and scientists use conditional selection with numpy to filter and analyze data efficiently.
Progress0 / 4 steps
1
Create the sales data array
Create a numpy array called sales with these exact values: [150, 200, 90, 300, 250]
NumPy
Need a hint?

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

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

Just assign the number 180 to the variable target.

3
Use np.where() to find days exceeding the target
Use np.where() with the condition sales > target and assign the result to a variable called days_above_target
NumPy
Need a hint?

Use np.where(condition) to get indices where the condition is true.

4
Print the days with sales above the target
Print the variable days_above_target to show the indices of days with sales above the target
NumPy
Need a hint?

Use print(days_above_target) to display the result.