Skip to main content

function

unsqueeze

unsqueeze(v: Symbol, axis: Int) -> Symbol

Inserts a size-1 dimension into a symbolic tensor.

Args:

  • v (Symbol): The input symbolic tensor to unsqueeze.
  • axis (Int): The index at which to insert a new dimension into the input's shape. Elements at that index or higher are shifted back. If negative, it indexes relative 1 plus the rank of the tensor. For example, unsqueeze(v, -1) adds a new dimension at the end, and unsqueeze(v, -2) inserts the dimension immediately before the last dimension.

Returns:

A symbolic tensor with the same muber of elements as the input tensor, whose rank is 1 larger than the rank of the input tensor. The result's shape at the axis dimension is a static dimension of size 1.