Ad

How To Use Append For 2D Arrays?

- 1 answer

I am trying to add array y to array x by this code:

import numpy as np

x = np.zeros((5,2))
y = np.array([[1,2]])
np.append(x , y)

But the result of x is yet:

array([[0., 0.],
       [0., 0.],
       [0., 0.],
       [0., 0.],
       [0., 0.]])

What is the problem?

Ad

Answer

Use np.concatenate:

import numpy as np

x = np.zeros((5,2))
y = np.array([[1,2]])
result = np.concatenate((x,y), axis = 0)
Ad
source: stackoverflow.com
Ad