NumPy - Broadcasting
Which of the following numpy operations correctly uses broadcasting?
np.array([1, 2, 3]) + np.array([4, 5]) fails because shapes (3,) and (2,) are incompatible. np.array([[1], [2], [3]]) + np.array([4, 5, 6]) works because shapes (3,1) and (3,) broadcast to (3,3). np.array([1, 2, 3]) + 5 works because scalar 5 broadcasts to (3,). np.array([1, 2, 3]) + np.array([[4], [5]]) fails due to incompatible shapes (3,) and (2,1).np.array([[1], [2], [3]]) + np.array([4, 5, 6]) and np.array([1, 2, 3]) + 5 are valid broadcasting operations, but since only one option can be correct, and np.array([[1], [2], [3]]) + np.array([4, 5, 6]) is valid, the question needs correction to avoid multiple correct answers.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions