NumPy ndarray itemset() Method | Insert Scalar in ndarray Last Updated : 12 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The NumPy ndarray.itemset() method inserts a scalar into an array. Key Points:ndarray.itemset function needs at least one argument.The last argument you pass in the function is considered an "item". arr.itemset(*args) is a quicker way to do same thing as arr[args] = item. The item should be a scalar value and args must select a single item in the array.Syntaxnumpy.ndarray.itemset(*args) Parameters: *args : If one argument: a scalar, only used in case arr is of size 1. If two arguments: the last argument is the value to be set and must be a scalar, the first argument specifies a single array element location. It is either an int or a tuple.ExamplesLet's look at this example of the ndarray.itemset() method of the NumPy library. Example 1: Python3 import numpy as np np.random.seed(345) arr = np.random.randint(9, size =(3, 3)) print("Input array : ", arr) arr.itemset(4, 0) print ("Output array : ", arr) Output : Input array : [[8 0 3] [8 4 3] [4 1 7]]Output array : [[8 0 3] [8 0 3] [4 1 7]]Example 2: Python3 # Python program explaining # numpy.ndarray.itemset() function # importing numpy as geek import numpy as geek geek.random.seed(345) arr = geek.random.randint(9, size =(3, 3)) print("Input array : ", arr) arr.itemset((2, 2), 9) print ("Output array : ", arr) Output: Input array : [[8 0 3] [8 4 3] [4 1 7]]Output array : [[8 0 3] [8 4 3] [4 1 9]]Note: While the ndarray.itemset method is fast and efficient, but many people avoid it because this method can complicate the code and it might waste space if the array is not fully populated. Create Quiz Comment S sanjoy_62 Follow 0 Improve S sanjoy_62 Follow 0 Improve Article Tags : Machine Learning Python-numpy Python numpy-ndarray python Explore Machine Learning BasicsIntroduction to Machine Learning8 min readTypes of Machine Learning7 min readWhat is Machine Learning Pipeline?6 min readApplications of Machine Learning3 min readPython for Machine LearningMachine Learning with Python Tutorial5 min readNumPy Tutorial - Python Library3 min readPandas Tutorial4 min readData Preprocessing in Python4 min readEDA - Exploratory Data Analysis in Python6 min readFeature EngineeringWhat is Feature Engineering?5 min readIntroduction to Dimensionality Reduction4 min readFeature Selection Techniques in Machine Learning4 min readSupervised LearningSupervised Machine Learning7 min readLinear Regression in Machine learning14 min readLogistic Regression in Machine Learning10 min readDecision Tree in Machine Learning8 min readRandom Forest Algorithm in Machine Learning5 min readK-Nearest Neighbor(KNN) Algorithm8 min readSupport Vector Machine (SVM) Algorithm9 min readNaive Bayes Classifiers6 min readUnsupervised LearningWhat is Unsupervised Learning5 min readK means Clustering â Introduction6 min readHierarchical Clustering in Machine Learning6 min readDBSCAN Clustering in ML - Density based clustering6 min readApriori Algorithm6 min readFrequent Pattern Growth Algorithm5 min readECLAT Algorithm - ML5 min readPrincipal Component Analysis (PCA)7 min readModel Evaluation and TuningEvaluation Metrics in Machine Learning9 min readRegularization in Machine Learning5 min readCross Validation in Machine Learning5 min readHyperparameter Tuning5 min readUnderfitting and Overfitting in ML3 min readBias and Variance in Machine Learning6 min readAdvanced TechniquesReinforcement Learning9 min readSemi-Supervised Learning in ML5 min readSelf-Supervised Learning (SSL)6 min readEnsemble Learning8 min readMachine Learning PracticeMachine Learning Interview Questions and Answers15+ min read100+ Machine Learning Projects with Source Code5 min read Like