Counting Non-Zero Elements with np.count_nonzero()
📖 Scenario: Imagine you work in a store that tracks daily sales of different products. Some days, some products sell zero items. You want to find out how many products sold at least one item each day.
🎯 Goal: You will create a numpy array representing daily sales, then use np.count_nonzero() to count how many products sold more than zero items each day.
📋 What You'll Learn
Create a numpy array called
daily_sales with the exact values given.Create a variable called
day_index to select a specific day.Use
np.count_nonzero() to count non-zero sales for the selected day.Print the count of products sold on that day.
💡 Why This Matters
🌍 Real World
Stores and businesses often track sales data daily. Counting how many products sold helps understand customer demand and stock management.
💼 Career
Data analysts and scientists use numpy functions like <code>np.count_nonzero()</code> to quickly analyze datasets and extract useful insights.
Progress0 / 4 steps