Skip to content
fn

unsqueeze_op

→TensorImplPtr
int unsqueeze_op(const int & a, int dim)

Python wrappers

Public Python APIs implemented by this engine symbol.

Insert a new size-1 dimension at a given position.

The new axis is added before position dim in the output, so the output rank is ndim + 1. Negative dim wraps relative to the output rank (so dim = -1 inserts before the last existing dimension).

See Also

squeeze_op, reshape_op.

Parameters

aTensorImplPtr
Input tensor.
dimint
Insertion position. Must satisfy -(ndim + 1) <= dim <= ndim.

Returns

TensorImplPtr

A view with rank ndim + 1 and a size-1 dimension inserted at dim.

Raises

IndexError
If dim is out of range.

Examples

A length-5 1-D tensor unsqueezed at ``dim=0`` becomes a ``(1, 5)`` view;
unsqueezed at ``dim=1`` becomes a ``(5, 1)`` view.