How to Add a New Value to a NumPy Array Last Updated : 11 Dec, 2024 Comments Improve Suggest changes Like Article Like Report Let's learn how to add a new value to a Numpy array. Adding elements in a NumPy array is not straightforward compared to adding them to standard Python lists. Adding Values to NumPy Array using np.append()The np.append() function is used to add new values at the end of an existing NumPy array. This method creates a new array with the appended value(s). Python import numpy as np arr = np.array([1, 2, 3]) # Append a new value new_arr = np.append(arr, 4) print(new_arr) Output[1 2 3 4] Apart from np.append() method, we can use the following methods for adding values to a NumPy array: Table of ContentUsing np.insert()Using np.concatenate()Using np.resize()Adding Values to NumPy Array using np.insert()The np.insert() function allows you to insert values at any specific index within the array. You can insert single or multiple values at a chosen position. Python import numpy as np arr = np.array([1, 2, 3]) # Insert a new value at index 1 new_arr = np.insert(arr, 1, 4) print(new_arr) Output[1 4 2 3] Adding Values to NumPy Array using np.concatenate()The np.concatenate() function can be used to add elements by combining two arrays. This is useful when you want to add a larger block of data. Python import numpy as np arr1 = np.array([1, 2, 3]) arr2 = np.array([4, 5]) # Concatenate arrays new_arr = np.concatenate((arr1, arr2)) print(new_arr) Output[1 2 3 4 5] Adding Values to NumPy Array using np.resize()The np.resize() function can be used to change the size of an array and fill new elements with a specified value. This method is useful when you need to expand the array to a larger size. Python import numpy as np arr = np.array([1, 2, 3]) # Resize and add a new value new_arr = np.resize(arr, 5) print(new_arr) Output[1 2 3 1 2] In this article, we covered four methods for adding new values to a NumPy array: np.append(), np.insert(), np.concatenate(), and np.resize(). Each method has its own specific use case, depending on whether you want to add values at the end, insert at a particular index, or expand the array with new data. Comment More infoAdvertise with us Next Article How to Add a New Value to a NumPy Array Y yasdbqs Follow Improve Article Tags : Numpy AI-ML-DS AI-ML-DS With Python Similar Reads Machine Learning Tutorial Machine learning is a branch of Artificial Intelligence that focuses on developing models and algorithms that let computers learn from data without being explicitly programmed for every task. In simple words, ML teaches the systems to think and understand like humans by learning from the data.It can 5 min read Linear Regression in Machine learning Linear regression is a type of supervised machine-learning algorithm that learns from the labelled datasets and maps the data points with most optimized linear functions which can be used for prediction on new datasets. It assumes that there is a linear relationship between the input and output, mea 15+ min read Support Vector Machine (SVM) Algorithm Support Vector Machine (SVM) is a supervised machine learning algorithm used for classification and regression tasks. It tries to find the best boundary known as hyperplane that separates different classes in the data. It is useful when you want to do binary classification like spam vs. not spam or 9 min read Logistic Regression in Machine Learning Logistic Regression is a supervised machine learning algorithm used for classification problems. Unlike linear regression which predicts continuous values it predicts the probability that an input belongs to a specific class. It is used for binary classification where the output can be one of two po 11 min read K means Clustering â Introduction K-Means Clustering is an Unsupervised Machine Learning algorithm which groups unlabeled dataset into different clusters. It is used to organize data into groups based on their similarity. Understanding K-means ClusteringFor example online store uses K-Means to group customers based on purchase frequ 4 min read K-Nearest Neighbor(KNN) Algorithm K-Nearest Neighbors (KNN) is a supervised machine learning algorithm generally used for classification but can also be used for regression tasks. It works by finding the "k" closest data points (neighbors) to a given input and makesa predictions based on the majority class (for classification) or th 8 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 100+ Machine Learning Projects with Source Code [2025] This article provides over 100 Machine Learning projects and ideas to provide hands-on experience for both beginners and professionals. Whether you're a student enhancing your resume or a professional advancing your career these projects offer practical insights into the world of Machine Learning an 5 min read Introduction to Convolution Neural Network Convolutional Neural Network (CNN) is an advanced version of artificial neural networks (ANNs), primarily designed to extract features from grid-like matrix datasets. This is particularly useful for visual datasets such as images or videos, where data patterns play a crucial role. CNNs are widely us 8 min read Naive Bayes Classifiers Naive Bayes is a classification algorithm that uses probability to predict which category a data point belongs to, assuming that all features are unrelated. This article will give you an overview as well as more advanced use and implementation of Naive Bayes in machine learning. Illustration behind 7 min read Like