Array API specification for manipulating arrays.
A conforming implementation of the array API standard must provide and support the following functions adhering to the following conventions.
- Positional parameters must be positional-only parameters. Positional-only parameters have no externally-usable name. When a function accepting positional-only parameters is called, positional arguments are mapped to these parameters based solely on their order.
- Optional parameters must be keyword-only arguments.
- Unless stated otherwise, functions must adhere to the type promotion rules defined in {ref}
type-promotion
.
(function-concat)=
Joins a sequence of arrays along an existing axis.
-
arrays: Union[Tuple[ <array>, ... ], List[ <array> ] ]
- input arrays to join. The arrays must have the same shape, except in the dimension specified by
axis
.
- input arrays to join. The arrays must have the same shape, except in the dimension specified by
-
axis: Optional[ int ]
- axis along which the arrays will be joined. If
axis
isNone
, arrays must be flattened before concatenation. Ifaxis
is negative, the function must determine the axis along which to join by counting from the last dimension. Default:0
.
- axis along which the arrays will be joined. If
-
out: <array>
-
an output array containing the concatenated values. If the input arrays have different data types, normal type promotion rules must apply. If the input arrays have the same data type, the output array must have the same data type as the input arrays.
This specification leaves type promotion between data type families (i.e., `intxx` and `floatxx`) unspecified.
-
(function-expand_dims)=
Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by axis
.
-
x: <array>
- input array.
-
axis: int
- axis position. Must follow Python's indexing rules: zero-based and negative indices must be counted backward from the last dimension. If
x
has rankN
, a validaxis
must reside on the interval[-N-1, N+1]
. AnIndexError
exception must be raised if provided an invalidaxis
position.
- axis position. Must follow Python's indexing rules: zero-based and negative indices must be counted backward from the last dimension. If
-
out: <array>
- an expanded output array having the same data type and shape as
x
.
- an expanded output array having the same data type and shape as
(function-flip)=
Reverses the order of elements in an array along the given axis. The shape of the array must be preserved.
-
x: <array>
- input array.
-
axis: Optional[ Union[ int, Tuple[ int, ... ] ] ]
- axis (or axes) along which to flip. If
axis
isNone
, the function must flip all input array axes. Ifaxis
is negative, the function must count from the last dimension. If provided more than one axis, the function must flip only the specified axes. Default:None
.
- axis (or axes) along which to flip. If
-
out: <array>
- an output array having the same data type and shape as
x
and whose elements, relative tox
, are reordered.
- an output array having the same data type and shape as
(function-reshape)=
Reshapes an array without changing its data.
-
x: <array>
- input array to reshape.
-
shape: Tuple[ int, ... ]
- a new shape compatible with the original shape. One shape dimension is allowed to be
-1
. When a shape dimension is-1
, the corresponding output array shape dimension must be inferred from the length of the array and the remaining dimensions.
- a new shape compatible with the original shape. One shape dimension is allowed to be
-
out: <array>
- an output array having the same data type, elements, and underlying element order as
x
.
- an output array having the same data type, elements, and underlying element order as
(function-roll)=
Rolls array elements along a specified axis. Array elements that roll beyond the last position are re-introduced at the first position. Array elements that roll beyond the first position are re-introduced at the last position.
-
x: <array>
- input array.
-
shift: Union[ int, Tuple[ int, ... ] ]
- number of places by which the elements are shifted. If
shift
is a tuple, thenaxis
must be a tuple of the same size, and each of the given axes must be shifted by the corresponding element inshift
. Ifshift
is anint
andaxis
a tuple, then the sameshift
must be used for all specified axes. If a shift is positive, then array elements must be shifted positively (toward larger indices) along the dimension ofaxis
. If a shift is negative, then array elements must be shifted negatively (toward smaller indices) along the dimension ofaxis
.
- number of places by which the elements are shifted. If
-
axis: Optional[ Union[ int, Tuple[ int, ... ] ] ]
- axis (or axes) along which elements to shift. If
axis
isNone
, the array must be flattened, shifted, and then restored to its original shape. Default:None
.
- axis (or axes) along which elements to shift. If
-
out: <array>
- an output array having the same data type as
x
and whose elements, relative tox
, are shifted.
- an output array having the same data type as
(function-squeeze)=
Removes singleton dimensions (axes) from x
.
-
x: <array>
- input array.
-
axis: Union[ int, Tuple[ int, ... ] ]
- axis (or axes) to squeeze. If a specified axis has a size greater than one, a
ValueError
must be raised.
- axis (or axes) to squeeze. If a specified axis has a size greater than one, a
-
out: <array>
- an output array having the same data type and elements as
x
.
- an output array having the same data type and elements as
(function-stack)=
Joins a sequence of arrays along a new axis.
-
arrays: Union[Tuple[ <array>, ... ], List[ <array> ] ]
- input arrays to join. Each array must have the same shape.
-
axis: int
- axis along which the arrays will be joined. Providing an
axis
specifies the index of the new axis in the dimensions of the result. For example, ifaxis
is0
, the new axis will be the first dimension and the output array will have shape(N, A, B, C)
; ifaxis
is1
, the new axis will be the second dimension and the output array will have shape(A, N, B, C)
; and, ifaxis
is-1
, the new axis will be the last dimension and the output array will have shape(A, B, C, N)
. A validaxis
must be on the interval[-N, N)
, whereN
is the rank (number of dimensions) ofx
. If provided anaxis
outside of the required interval, the function must raise an exception. Default:0
.
- axis along which the arrays will be joined. Providing an
-
out: <array>
-
an output array having rank
N+1
, whereN
is the rank (number of dimensions) ofx
. If the input arrays have different data types, normal type promotion rules must apply. If the input arrays have the same data type, the output array must have the same data type as the input arrays.This specification leaves type promotion between data type families (i.e., `intxx` and `floatxx`) unspecified.
-