Recall & Review
beginner
What is broadcasting in NumPy?
Broadcasting is a way that NumPy allows arrays of different shapes to work together in arithmetic operations by automatically expanding the smaller array to match the shape of the larger one.
Click to reveal answer
beginner
Why is broadcasting important in data science?
Broadcasting lets you write simple and fast code without manually reshaping arrays. It helps perform operations on large datasets efficiently, saving time and memory.
Click to reveal answer
intermediate
How does broadcasting improve performance?
Broadcasting avoids creating large temporary arrays by reusing data smartly. This reduces memory use and speeds up calculations.
Click to reveal answer
beginner
Example: What happens when you add a 1D array to a 2D array using broadcasting?
NumPy automatically expands the 1D array across the rows or columns of the 2D array so the shapes match, then adds element-wise.
Click to reveal answer
intermediate
What are the rules NumPy follows to decide if broadcasting can happen?
NumPy compares array shapes from right to left. Dimensions must be equal or one of them must be 1. If these rules hold for all dimensions, broadcasting works.
Click to reveal answer
What does broadcasting allow you to do in NumPy?
✗ Incorrect
Broadcasting lets you do element-wise operations on arrays with different shapes by expanding the smaller array automatically.
Which of these shape pairs can be broadcast together? (3,1) and (1,4)
✗ Incorrect
Broadcasting works if each dimension is equal or one is 1. Here, 3 vs 1 and 1 vs 4 are compatible.
Why does broadcasting save memory?
✗ Incorrect
Broadcasting reuses the smaller array's data instead of copying it many times, saving memory.
If you add a (3,) array to a (5,3) array, what shape will the result have?
✗ Incorrect
The (3,) array is broadcast across the second dimension to match (5,3), so the result shape is (5,3).
Which of these is NOT a broadcasting rule?
✗ Incorrect
Arrays can have different numbers of dimensions; NumPy prepends 1s to the smaller shape to match dimensions.
Explain in your own words why broadcasting is useful when working with arrays of different shapes.
Think about how you can add or multiply arrays without writing loops.
You got /4 concepts.
Describe the basic rules NumPy uses to decide if two arrays can be broadcast together.
Focus on how dimensions match or stretch.
You got /4 concepts.