Hasani
Hasani

Reputation: 3869

How to use append for 2D arrays?

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?

Upvotes: 1

Views: 429

Answers (2)

K.Maj
K.Maj

Reputation: 200

Use np.concatenate:

import numpy as np

x = np.zeros((5,2))
y = np.array([[1,2]])
result = np.concatenate((x,y), axis = 0)

Upvotes: 1

naivepredictor
naivepredictor

Reputation: 898

x = np.append(x, y)

you are missing x assignment

Upvotes: 1

Related Questions