promptdojo_

Broadcasting and vectorization — step 7 of 7

Checkpoint

One last thing before we move on. Same surface as a write step — but the lesson doesn't complete until this passes.

Implement broadcast_shape(a, b): align both shape tuples from the right (missing dims count as 1); each position is compatible when equal or either is 1 (result: the max); any other pair returns the string "error"; otherwise return the full result shape tuple. Print all four cases in the format "(3, 2) + (2,) -> (3, 2)". The last case is the famous one: (3,) + (3, 1) doesn't error — it quietly makes (3, 3).

full-screen editor opens — close anytime to keep reading.