In [1]:
import numpy as np
A = np.arange(1, 9).reshape(2, -1)
print(A)
Use np.array
to create the array
B = [1 2]
In [2]:
B = np.array([1, 2])
print(B)
Use broadcasting to add B
to A
to create the final array
A + B = [[2 3 4 5]
[7 8 9 10]
Hint: what shape does B
have to be changed to?
In [3]:
print(A + B.reshape(2, 1))