Broadcasting for Outer Products
📖 Scenario: Imagine you run a small bakery. You want to find out how many cookies you can make if you combine different numbers of dough balls with different baking trays. Each dough ball makes one cookie, and each tray can bake a certain number of cookies at once.
🎯 Goal: You will create two arrays: one for the number of dough balls and one for the number of trays. Then, you will use broadcasting to calculate the total number of cookies you can bake for every combination of dough balls and trays.
📋 What You'll Learn
Create a numpy array called
dough_balls with values [2, 4, 6]Create a numpy array called
baking_trays with values [1, 3, 5]Use broadcasting to calculate the outer product of
dough_balls and baking_traysStore the result in a variable called
total_cookiesPrint the
total_cookies array💡 Why This Matters
🌍 Real World
Bakers and food businesses often need to calculate production quantities for different ingredient and equipment combinations quickly.
💼 Career
Data scientists use broadcasting to perform efficient calculations on large datasets without writing slow loops.
Progress0 / 4 steps