简体   繁体   中英

How to insert a numpy array to a numpy array of arrays?

I have a simple question here, I have three arrays,

a = np.array([1,2,3])
b = np.array([4,5,6])
c = np.array([7,8,9])
d = np.array([6,6,6])

I combine a,b,c to another array say e,

e = np.array([a,b,c])

I want d to be inserted to e so that I get the following output,

[[1, 2, 3], [4, 5, 6], [7, 8, 9], [6,6,6]]

Use numpy.append that appends to the end of array:

e = np.append(e, [d], axis=0)

Note as quoted from docs:

Append values to the end of an array. When axis is specified, values must have the correct shape.

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