I have these arrays.
a = np.array([[1,2,3],[3,4,5],[4,5,6]])
b = np.array([-1, -2, -3])
I want to change the some of elements of a with the elements of b like so:
a = [[1, -1, -1],
[3, -2, -2],
[4, -3, -3]]
I tried: a[:,1:]=b but got an exception:
ValueError: could not broadcast input array from shape (3) into shape (3,2)
What is the correct way to broadcast b into a?
a[:, 1:] = b[:, None]makeb(3,1) shapeda[:, 1:] = b.Tto reshape to (3,1) but that did not work. Why did it not work? Seem thatb[:, None]is the way to transpose a row vector to a column vector.