promptdojo_

Broadcasting and vectorization — step 6 of 7

Write broadcast_add(matrix, vec): add the vector to every row — but FIRST check that len(vec) matches the row length, raising ValueError(f"{len(vec)} vs {len(matrix[0])} on the last dim") on mismatch. Print the valid (3,2)+(2,) result, then catch and print the error for the tempting-but-wrong (3,2)+(3,) case.

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