numpy.put () in Python



numpy.put (array, indices, p_array, mode = & # 39; boost & # 39;): replaces specific array elements with given p_array values. An indexed array works on a flat 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 

# Python program explaining
# numpy.put ()

 

import numpy as geek

 

a = geek.arange ( 5  )

geek.put (a, [ 0 , 2 ], [ - 44 , - 55 ])

print ( "After put:" , a)

Output:

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

Output:

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

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

Notes:
uh These codes will not work for online IDs. Please run them on your systems to see how they work.
,
This article is provided by Mohit Gupta_OMG


# Python program explaining
# numpy.put ()

 

import numpy as geek

  

a = geek.arange ( 5 )

geek.put (a, 22 , - 5 , mode = `clip` )

print ( "After put:" , a)