In this article, we will discuss different ways to add / append single element in a numpy array by using append() or concatenate() or insert() function.
Table of Contents
 Use append() to add an element to Numpy Array.
 Use concatenate() to add an element to Numpy Array.
 Use insert() to add an element to Numpy Array.
Add element to Numpy Array using append()
Numpy module in python, provides a function to numpy.append() to add an element in a numpy array. We can pass the numpy array and a single value as arguments to the append() function. It doesn’t modifies the existing array, but returns a copy of the passed array with given value added to it. For example,
import numpy as np # Create a Numpy Array of integers arr = np.array([11, 2, 6, 7, 2]) # Add / Append an element at the end of a numpy array new_arr = np.append(arr, 10) print('New Array: ', new_arr) print('Original Array: ', arr)
Output:
New Array: [11 2 6 7 2 10] Original Array: [11 2 6 7 2]
The append() function created a copy of the array, then added the value 10 at the end of it and final returned it.
Add element to Numpy Array using concatenate()
Numpy module in python, provides a function numpy.concatenate() to join two or more arrays. We can use that to add single element in numpy array. But for that we need to encapsulate the single value in a sequence data structure like list and pass a tuple of array & list to the concatenate() function. For example,
import numpy as np # Create a Numpy Array of integers arr = np.array([11, 2, 6, 7, 2]) # Add / Append an element at the end of a numpy array new_arr = np.concatenate( (arr, [10] ) ) print('New Array: ', new_arr) print('Original Array: ', arr)
Output:
New Array: [11 2 6 7 2 10] Original Array: [11 2 6 7 2]
It returned a new array containing values from both sequences i.e. array and list. It didn’t modified the original array, but returned a new array containing all values from original numpy array and a single value added along with them in the end.
Add element to Numpy Array using insert()
Using numpy.insert() function in the NumPy module, we can also insert an element at the end of a numpy array. For example,
C
Output:
O
We passed three arguments to the insert() function i.e. a numpy array, index position and value to be added. It returned a copy of array arr with value added at the given index position. As in this case we wanted to add the element at the end of array, so as the index position, we passed the size of array. Therefore it added the value at the end of array.
Important point is that it did not modifies the original array, it returned a copy of the original array arr with given value added at the specified index i.e. as the end of array.
Summary:
We learned about three different ways to append single element at the end of a numpy array in python.
Pandas Tutorials Learn Data Analysis with Python

Pandas Tutorial Part #1  Introduction to Data Analysis with Python

Pandas Tutorial Part #2  Basics of Pandas Series

Pandas Tutorial Part #3  Get & Set Series values

Pandas Tutorial Part #4  Attributes & methods of Pandas Series

Pandas Tutorial Part #5  Add or Remove Pandas Series elements

Pandas Tutorial Part #6  Introduction to DataFrame

Pandas Tutorial Part #7  DataFrame.loc[]  Select Rows / Columns by Indexing

Pandas Tutorial Part #8  DataFrame.iloc[]  Select Rows / Columns by Label Names

Pandas Tutorial Part #9  Filter DataFrame Rows

Pandas Tutorial Part #10  Add/Remove DataFrame Rows & Columns

Pandas Tutorial Part #11  DataFrame attributes & methods

Pandas Tutorial Part #12  Handling Missing Data or NaN values

Pandas Tutorial Part #13  Iterate over Rows & Columns of DataFrame

Pandas Tutorial Part #14  Sorting DataFrame by Rows or Columns

Pandas Tutorial Part #15  Merging or Concatenating DataFrames

Pandas Tutorial Part #16  DataFrame GroupBy explained with examples
Are you looking to make a career in Data Science with Python?
Data Science is the future, and the future is here now. Data Scientists are now the most soughtafter professionals today. To become a good Data Scientist or to make a career switch in Data Science one must possess the right skill set. We have curated a list of Best Professional Certificate in Data Science with Python. These courses will teach you the programming tools for Data Science like Pandas, NumPy, Matplotlib, Seaborn and how to use these libraries to implement Machine learning models.
Checkout the Detailed Review of Best Professional Certificate in Data Science with Python.
Remember, Data Science requires a lot of patience, persistence, and practice. So, start learning today.