expand_dims

expand_dims(x: array, /, *, axis: int = 0) array

Expands the shape of an array by inserting a new axis (dimension) of size one at the position specified by axis.

Parameters:
  • x (array) – input array.

  • axis (int) – axis position (zero-based). If x has rank (i.e, number of dimensions) N, a valid axis must reside on the closed-interval [-N-1, N]. If provided a negative axis, the axis position at which to insert a singleton dimension must be computed as N + axis + 1. Hence, if provided -1, the resolved axis position must be N (i.e., a singleton dimension must be appended to the input array x). If provided -N-1, the resolved axis position must be 0 (i.e., a singleton dimension must be prepended to the input array x).

Returns:

out (array) – an expanded output array having the same data type as x.

Raises:

IndexError – If provided an invalid axis position, an IndexError should be raised.