lesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorizationlesson 2 of 4 · broadcasting and vectorization
Checkpoint
One last thing before we move on. pass this to mark the lesson done, or skip and keep moving. hop to the next when you're ready.
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).