numpy.append() function with example in python

Spread the love

numpy.append(): This function append values to the end of an array.

syntax: numpy.append(arr, values, axis=None)

Parameters:
arr : array_like
Values are appended to a copy of this array.

values : array_like
These values are appended to a copy of arr. It must be of the correct shape (the same shape as arr, excluding axis). If axis is not specified, values can be any shape and will be flattened before use.

axis : int, optional
The axis along which values are appended. If axis is not given, both arr and values are flattened before use.

Returns:
append : ndarray
A copy of arr with values appended to axis. Note that append does not occur in-place: a new array is allocated and filled. If axis is None, out is a flattened array.

import numpy as np a= np.array([1,2]) b= np.append(a,[2,3]) print(b)

Output:

[1 2 2 3]

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *