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
# 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 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])
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.
Recommended Posts:
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
- Python - Read blob object in python using wand library
- Python | Convert list to Python array
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- twitter-text-python (ttp) module - Python
- MySQL-Connector-Python module in Python
- Python | Index of Non-Zero elements in Python list
- Python | Merge Python key values to list
- Python | PRAW - Python Reddit API Wrapper
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- set add() in python
- Use of min() and max() in Python
- Python Try Except
- chr() in Python

