Broadcasting Rules
Arrays with different shapes work together when each dimension matches or is 1.
Example
a = np.arange(6).reshape(2, 3)
print(a + np.array([10, 20, 30]))
print(a * np.array([[1], [10]]))Result
[[10 21 32] [13 24 35]] [[ 0 1 2] [30 40 50]]
Exercise
Add a row.
a + np.array([1, 2, ])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.