Bird
0
0

Which broadcasting operation correctly achieves this?

hard📝 Application Q8 of 15
NumPy - Broadcasting
You have a dataset with shape (100, 1) representing 100 samples and a feature vector of shape (5,). You want to add the feature vector to each sample. Which broadcasting operation correctly achieves this?
AAdd the (100,1) array to the (5,1) reshaped feature vector
BAdd the (100,1) array directly to the (5,) feature vector
CAdd the (100,) array to the (5,) feature vector
DAdd the (1,100) array to the (5,) feature vector
Step-by-Step Solution
Solution:
  1. Step 1: Understand shapes

    Dataset shape is (100,1), feature vector is (5,). Adding directly broadcasts (5,) to (1,5).
  2. Step 2: Confirm broadcasting

    Adding (100,1) + (5,) broadcasts to (100,5), adding feature vector to each sample.
  3. Final Answer:

    Add the (100,1) array directly to the (5,) feature vector -> Option B
  4. Quick Check:

    Broadcasting (100,1) + (5,) = (100,5) [OK]
Quick Trick: Add (100,1) + (5,) to broadcast features per sample [OK]
Common Mistakes:
  • Reshaping unnecessarily
  • Confusing feature vector shape
  • Assuming shapes must match exactly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes