Open In App

numpy.put() in Python

Last Updated : 08 Mar, 2024
Suggest changes
Share
Like Article
Like
Report

The numpy.put() function replaces specific elements of an array with given values of p_array. Array indexed works on flattened array. 
 

Syntax: numpy.put(array, indices, p_array, mode = 'raise')


Parameters : 

array : array_like, target array indices : index of the values to be fetched p_array : array_like, values to be placed in target array mode : [{‘raise’, ‘wrap’, ‘clip’}, optional] mentions how out-of-bound indices will behave raise : [default]raise an error wrap : wrap around clip : clip to the range


 

Python
# Python Program explaining # numpy.put() import numpy as geek a = geek.arange(5) geek.put(a, [0, 2], [-44, -55]) print("After put : \n", a) 

Output : 

After put : [-44, 1, -55, 3, 4]


 

Python
# Python Program explaining # numpy.put() import numpy as geek a = geek.arange(5) geek.put(a, 22, -5, mode='clip') print("After put : \n", a) 

Output : 

array([ 0, 1, 2, 3, -5])


Note : 
These codes won't run on online IDE's. So please, run them on your systems to explore the working.
 


Explore