take_along_axis¶
- take_along_axis(x: array, indices: array, /, *, axis: int = -1) array¶
Returns elements from an array at the one-dimensional indices specified by
indicesalong a providedaxis.- Parameters:
x (array) – input array. Must be compatible with
indices, except for the axis (dimension) specified byaxis(see Broadcasting).indices (array) – array indices. Must have the same rank (i.e., number of dimensions) as
x. If an index is negative, the function must determine the element to select along a specified axis (dimension) by counting from the last element (where-1refers to the last element).axis (int) – axis along which to select values. If
axisis negative, the function must determine the axis along which to select values by counting from the last dimension (where-1refers to the last dimension). Default:-1.
- Returns:
out (array) – an array having the same data type as
x. Must have the same rank (i.e., number of dimensions) asxand must have a shape determined according to Broadcasting, except for the axis (dimension) specified byaxiswhose size must equal the size of the corresponding axis (dimension) inindices.
Notes
This specification does not require bounds checking. The behavior for out-of-bounds indices is left unspecified.
New in version 2024.12.