expand_dims¶
- expand_dims(x: array, /, *, axis: int = 0) array ¶
Expands the shape of an array by inserting a new axis of size one at the position specified by
axis
.- Parameters:
x (array) – input array.
axis (int) – axis position (zero-based). A valid
axis
must reside on the closed-interval[-N-1, N]
, whereN
is the number of axes inx
. If an axis is specified as a negative integer, the axis position at which to insert a singleton dimension must be computed asN + axis + 1
. Hence, if provided-1
, the resolved axis position must beN
(i.e., a singleton dimension must be appended to the input arrayx
). If provided-N-1
, the resolved axis position must be0
(i.e., a singleton dimension must be prepended to the input arrayx
). If provided an invalid axis, the function must raise an exception. Default:0
.
- Returns:
out (array) – an expanded output array. Must have the same data type as
x
.- Raises:
IndexError – If provided an invalid
axis
, anIndexError
should be raised.