0
0
NumPydata~15 mins

Logical operations (and, or, not) in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Logical Operations with NumPy Arrays
📖 Scenario: Imagine you work in a store that tracks daily sales of two products. You want to find days when certain sales conditions are met using logical operations.
🎯 Goal: You will create two NumPy arrays representing daily sales of two products. Then, you will use logical and, or, and not operations to find days matching specific sales conditions.
📋 What You'll Learn
Create two NumPy arrays named product_a_sales and product_b_sales with exact daily sales values.
Create a threshold variable named threshold with the exact value 50.
Use logical operations np.logical_and, np.logical_or, and np.logical_not on the sales arrays.
Print the final results arrays exactly as specified.
💡 Why This Matters
🌍 Real World
Stores and businesses often analyze sales data to find days when multiple products perform well or need attention.
💼 Career
Data analysts and scientists use logical operations on arrays to filter and analyze large datasets efficiently.
Progress0 / 4 steps
1
Create sales data arrays
Import NumPy as np. Create two NumPy arrays called product_a_sales and product_b_sales with these exact values: [30, 60, 45, 80, 55] and [20, 70, 50, 40, 65] respectively.
NumPy
Need a hint?

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

2
Set sales threshold
Create a variable called threshold and set it to the integer value 50.
NumPy
Need a hint?

Just assign the number 50 to the variable named threshold.

3
Apply logical operations
Create three variables: both_above using np.logical_and to find days when both products have sales above threshold, either_above using np.logical_or to find days when either product has sales above threshold, and not_a_above using np.logical_not to find days when product A sales are NOT above threshold.
NumPy
Need a hint?

Use comparisons like product_a_sales > threshold inside the logical functions.

4
Print the results
Print the variables both_above, either_above, and not_a_above each on a separate line in this order.
NumPy
Need a hint?

Use three separate print() statements for each variable in the order given.