take¶
- take(x: array, indices: array, /, *, axis: int | None = None) array ¶
Returns elements of an array along an axis.
- Parameters:
x (array) – input array. Should have one or more axes.
indices (array) – array indices. The array must be one-dimensional and have an integer data type. If an index is negative, the function must determine the element to select along a specified axis by counting from the last element (where
-1
refers to the last element).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 axis (where-1
refers to the last axis).If
x
is a one-dimensional array, providing anaxis
must be optional; however, ifx
has more than one axis, providing anaxis
must be required.
- Returns:
out (array) – an array having the same data type as
x
. The output array must have the same number of axes asx
and must have the same shape asx
, except for the axis specified byaxis
whose size must equal the number of elements inindices
.
Notes
This specification does not require bounds checking. The behavior for out-of-bounds indices is unspecified and thus implementation-defined.
When
x
is a zero-dimensional array, behavior is unspecified and thus implementation-defined.
New in version 2022.12.
Changed in version 2023.12: Out-of-bounds behavior is explicitly left unspecified.
Changed in version 2024.12: Behavior when provided a zero-dimensional input array is explicitly left unspecified.
Changed in version 2024.12: Clarified support for negative indices.