AI & Machine Learning NumPy Broadcasting & Vectorization Quiz

Broadcasting lets NumPy combine arrays of different shapes without loops, and it is behind most feature scaling and distance code in machine learning. This quiz tests the broadcasting rules, the shapes they produce and the errors you get when shapes do not line up.

Medium 10 questions ~6 minutes Pass at 80%

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
b = np.array([10, 20, 30])
print((a + b).tolist())
Show the answer

A. [[11, 22, 33], [14, 25, 36]] b has shape (3,), which matches the last dimension of a (2, 3), so it is added to every row. Adding a different number to each row would need a column of shape (2, 1).

What this quiz covers

  • The broadcasting rule, compared from the trailing dimension
  • Row vectors, column vectors and the shapes they make
  • Centering data with X - X.mean(axis=0)
  • np.where() instead of an if inside a loop
  • Why in-place operations can fail on integer arrays

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.