简体   繁体   中英

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?

x = np.append(x, y)

您缺少x作业

Use np.concatenate :

import numpy as np

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM