numpy.take() in Python
numpy.take(array, indices, axis = None, out = None, mode =’raise’) : Return elememts from array along the mentioned axis and indices.
Parameters :
array : array_like, input array
indices : index of the values to be fetched
axis : [int, optional] axis over which we need to fetch the elements;
By Default[axis = None], flattened input is used
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
out : [ndarray, optional]to place result within array
Returns :
ndarray; array has the same type
# Python Program illustrating # numpy.take method import numpy as geek #array = geek.arange(10).reshape(2, 5) array = [[5, 6, 2, 7, 1], [4, 9, 2, 9, 3]] print("Original array : \n", array) # indices = [0, 4] print("\nTaking Indices\n", geek.take(array, [0, 4])) # indices = [0, 4] with axis = 1 print("\nTaking Indices\n", geek.take(array, [0, 4], axis = 1)) |
Output :
Original array : [[5, 6, 2, 7, 1], [4, 9, 2, 9, 3]] Taking Indices [5 1] Taking Indices [[5 1] [4 3]]
References :
https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.take.html#numpy.take
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:
- Python | Index of Non-Zero elements in Python list
- Reading Python File-Like Objects from C | Python
- Python | Convert list to Python array
- Python | Merge Python key values to list
- Important differences between Python 2.x and Python 3.x with examples
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to Python Libraries
- Python | Add Logging to a Python Script
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Visualizing O(n) using Python
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- Any & All in Python
- SHA in Python
- abs() in Python
- pow() in Python



