Let’s say I have a NumPy array, a:
a
a = np.array([ [1, 2, 3], [2, 3, 4] ])
And I would like to add a column of ze
Assuming M is a (100,3) ndarray and y is a (100,) ndarray append can be used as follows:
M
y
append
M=numpy.append(M,y[:,None],1)
The trick is to use
y[:, None]
This converts y to a (100, 1) 2D array.
M.shape
now gives
(100, 4)