numpy.take() in Python
Improve
The numpy.take() function returns elements from array along the mentioned axis and indices.
Syntax: numpy.take(array, indices, axis = None, out = None, mode ='raise')
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
# Python Program illustrating# numpy.take methodimport 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 = 1print("\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 IDE’s. So please, run them on your systems to explore the working.
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills, become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Share your thoughts in the comments

