latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.unsqueeze
- tensorplay.functional.unsqueeze(input, dim) Tensor[source]
Returns a new tensor with a dimension of size one inserted at the specified position.
The returned tensor shares the same underlying data with this tensor.
A
dimvalue within the range[-input.dim() - 1, input.dim() + 1)can be used. Negativedimwill correspond tounsqueeze()applied atdim=dim + input.dim() + 1.- Parameters:
Example:
>>> x = tensorplay.tensor([1, 2, 3, 4]) >>> tensorplay.unsqueeze(x, 0) tensor([[ 1, 2, 3, 4]]) >>> tensorplay.unsqueeze(x, 1) tensor([[ 1], [ 2], [ 3], [ 4]])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

