1D and 2D broadcasting
📖 Scenario: You work in a small bakery that tracks daily sales of different types of bread. You want to analyze the sales data to understand how many breads were sold each day and how the prices affect total revenue.
🎯 Goal: Build a small program using numpy to apply 1D and 2D broadcasting. You will create arrays for daily sales and prices, then calculate total revenue using broadcasting.
📋 What You'll Learn
Create a 2D numpy array called
sales representing the number of breads sold for 3 types over 4 days.Create a 1D numpy array called
prices representing the price of each bread type.Use broadcasting to calculate the total revenue per day for each bread type.
Print the resulting revenue array.
💡 Why This Matters
🌍 Real World
Broadcasting helps quickly perform operations on sales and price data without writing loops, saving time and reducing errors.
💼 Career
Data analysts and scientists use broadcasting in numpy to efficiently handle and analyze multi-dimensional data like sales, prices, and revenues.
Progress0 / 4 steps