take¶
- take(x: array, indices: array, /, *, axis: int | None = None) array ¶
Returns elements of an array along an axis.
Note
Conceptually,
take(x, indices, axis=3)
is equivalent tox[:,:,:,indices,...]
; however, explicit indexing via arrays of indices is not currently supported in this specification due to concerns regarding__setitem__
and array mutation semantics.- Parameters:
x (array) – input array.
indices (array) –
array indices. The array must be one-dimensional and have an integer data type.
Note
This specification does not require bounds checking. The behavior for out-of-bounds indices is left unspecified.
axis (Optional[int]) –
axis over which to select values. If
axis
is negative, the function must determine the axis along which to select values by counting from the last dimension.If
x
is a one-dimensional array, providing anaxis
is optional; however, ifx
has more than one dimension, providing anaxis
is required.
- Returns:
out (array) – an array having the same data type as
x
. The output array must have the same rank (i.e., number of dimensions) asx
and must have the same shape asx
, except for the axis specified byaxis
whose size must equal the number of elements inindices
.
Notes
New in version 2022.12.
Changed in version 2023.12: Out-of-bounds behavior is explicitly left unspecified.