numpy.put() in Python

numpy.put(array, indices, p_array, mode = ‘raise’) : Replaces specific elements of an array with given values of p_array. Array indexed works on flattened array.
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

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

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

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :



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

Code Source :
https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.put.html#numpy.put

Note :
These codes won’t run on online-ID. Please run them on your systems to explore the working
.
This article is contributed by Mohit Gupta_OMG 😀. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.