mubas007
mubas007

Reputation: 131

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]]

Upvotes: 1

Views: 27

Answers (1)

Austin
Austin

Reputation: 26057

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.

Upvotes: 2

Related Questions