.append()
StevenSwiniarski474 total contributions
Published May 25, 2022
Contribute to Docs
The .append()
function adds values to the end of an array and returns a ndarray
with the values appended.
Syntax
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.
Example
The example below creates two ndarrays
and appends one to the other.
import numpy as npnd1 = np.array([[1,2,3],[4,5,6]])nd2 = np.array([[7,8,9]])print(nd1)print(nd2)print(np.append(nd1,nd2,0))
This produces the following output:
[[1 2 3][4 5 6]][[7 8 9]][[1 2 3][4 5 6][7 8 9]]
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.