Adding value of single numpy array to all columns in other numpy array
This can be done with a little help from broadcasting
by adding a new axis to B
(either with None
or with np.newaxis
) so that they have compatible shapes, and B
is broadcastable accross the larger array A
:
A + B[:,None]
array([[11, 12, 13, 14],
[25, 26, 27, 28],
[39, 40, 41, 42]])