The .append() function adds values to the end of an array and returns a ndarray with the values appended.


numpy.append(array, values, axis)

Where array is the array being appended to. The values parameter is another array specifying the values to add to array. If axis is specified, values must be the same shape as array without that axis. If axis is not specified, values can be any shape, and both array and values will be flattened before the values are appended. The axis value specifies the axis along which values are appended.


The example below creates two ndarrays and appends one to the other.

import numpy as np
nd1 = np.array([[1,2,3],[4,5,6]])
nd2 = np.array([[7,8,9]])

This produces the following output:

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


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python:NumPy on Codecademy