Recall & Review
beginner
What is broadcasting in numpy?
Broadcasting is a way numpy allows operations between arrays of different shapes by automatically expanding the smaller array to match the larger one without copying data.
Click to reveal answer
beginner
How does 1D broadcasting work when adding a 1D array to a 2D array?
The 1D array is stretched across the matching dimension of the 2D array so each row or column adds the 1D array element-wise.
Click to reveal answer
intermediate
What shape rules must be met for broadcasting to work?
Starting from the trailing dimensions, the sizes must be equal or one of them must be 1 for each dimension.
Click to reveal answer
intermediate
Example: What happens when you add a (3,1) array to a (1,4) array?
They broadcast to a (3,4) array by stretching the first array across columns and the second across rows, then adding element-wise.
Click to reveal answer
beginner
Why is broadcasting useful in data science?
It allows fast, memory-efficient operations on arrays without explicit loops, making code simpler and faster.
Click to reveal answer
What does numpy broadcasting allow you to do?
✗ Incorrect
Broadcasting lets numpy perform operations on arrays of different shapes by expanding the smaller array automatically.
If you add a (3,) array to a (3,4) array, how does broadcasting work?
✗ Incorrect
Broadcasting works because (3,) is treated as (1,3) and is broadcast across each row of the (3,4) array.
Which shape pair can broadcast together?
✗ Incorrect
Shapes (2,3) and (3,) broadcast because (3,) is treated as (1,3) and 1 can be stretched to 2.
What happens if broadcasting rules are not met?
✗ Incorrect
If shapes are incompatible, numpy raises a ValueError explaining the mismatch.
Which numpy function can help check array shapes before broadcasting?
✗ Incorrect
numpy.broadcast_shapes returns the broadcasted shape or raises an error if shapes are incompatible.
Explain in your own words how 1D and 2D arrays can be added using broadcasting in numpy.
Think about how numpy matches dimensions from the end and stretches arrays.
You got /4 concepts.
Describe the rules numpy uses to decide if two arrays can be broadcast together.
Focus on how numpy compares each dimension starting from the right.
You got /3 concepts.