Take elements from an array along an axis.
This function does the same thing as “fancy” indexing (indexing arrays using arrays); however, it can be easier to use if you need elements along a given axis.
Parameters: | a : array_like
indices : array_like, int
axis : int, optional
out : ndarray, optional
mode : {‘raise’, ‘wrap’, ‘clip’}, optional
|
---|---|
Returns: | subarray : ndarray
|
See also
Examples
>>> a = [4, 3, 5, 7, 6, 8]
>>> indices = [0, 1, 4]
>>> np.take(a, indices)
array([4, 3, 6])
In this example if a is a ndarray, “fancy” indexing can be used. >>> a = np.array(a) >>> a[indices] array([4, 3, 6])