dpctl.tensor.expand_dims(x, axis)[source]

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

  • x (usm_ndarray) – input array

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


Returns a view, if possible, and a copy otherwise with the number of dimensions increased. The expanded array has the same data type as the input array x. The expanded array is located on the same device as the input array, and has the same USM allocation type.

Return type:



IndexError – if axis value is invalid.