Append a 1d array to a 2d array in Numpy Python Append a 1d array to a 2d array in Numpy Python numpy numpy

Append a 1d array to a 2d array in Numpy Python


You want vstack:

In [45]: a = np.array([[1,2,3]])In [46]: l = [4,5,6]In [47]: np.vstack([a,l])Out[47]: array([[1, 2, 3],       [4, 5, 6]])

You can stack multiple rows on the condition that The arrays must have the same shape along all but the first axis.

In [53]: np.vstack([a,[[4,5,6], [7,8,9]]])Out[53]: array([[1, 2, 3],       [4, 5, 6],       [4, 5, 6],       [7, 8, 9]])


Try this:

np.concatenate(([a],[b]),axis=0)

when

a = np.array([1,2,3])b = np.array([4,5,6])

then result should be:

array([[1, 2, 3], [4, 5, 6]])