Broadcasting errors and debugging
📖 Scenario: Imagine you are working with sales data for a small store. You have daily sales numbers and want to apply a discount factor to each day's sales to see the adjusted sales. However, sometimes the shapes of your data arrays don't match, causing errors.
🎯 Goal: You will create two numpy arrays representing sales and discount factors. Then you will identify and fix a broadcasting error by adjusting the shape of the discount array. Finally, you will print the corrected adjusted sales.
📋 What You'll Learn
Create a numpy array called
sales with values [100, 200, 300]Create a numpy array called
discounts with values [0.9, 0.8]Create a new array
adjusted_sales by multiplying sales and discounts with correct shapes to avoid broadcasting errorsPrint the
adjusted_sales array💡 Why This Matters
🌍 Real World
In real data science, you often combine data arrays of different shapes. Understanding broadcasting helps you avoid errors and write efficient code.
💼 Career
Data scientists and analysts frequently manipulate arrays and matrices. Debugging broadcasting errors is a key skill to ensure correct calculations.
Progress0 / 4 steps