Aggregation along specific axes
📖 Scenario: You work in a small bakery that tracks daily sales of three types of bread over a week. You want to analyze the total sales per bread type and per day to understand which bread is most popular and which day has the highest sales.
🎯 Goal: Build a program that creates a 2D array of sales data, then calculates the total sales per bread type and per day using aggregation along specific axes.
📋 What You'll Learn
Create a 2D numpy array called
sales with exact values representing sales of three bread types over seven days.Create a variable called
axis_bread set to 0 to represent aggregation along bread types.Use
np.sum with axis=axis_bread to calculate total sales per day and store it in total_per_day.Create a variable called
axis_day set to 1 to represent aggregation along days.Use
np.sum with axis=axis_day to calculate total sales per bread type and store it in total_per_bread.Print
total_per_day and total_per_bread to show the results.💡 Why This Matters
🌍 Real World
Aggregating sales data helps businesses understand trends and make decisions about inventory and marketing.
💼 Career
Data analysts and scientists often aggregate data along specific axes to summarize and interpret multi-dimensional datasets.
Progress0 / 4 steps