unsqueeze¶
- nvtripy.unsqueeze(input: Tensor, dim: int) Tensor[source]¶
Returns a new tensor with the contents of the input tensor with a singleton dimension inserted before the specified axis.
- Parameters:
input (Tensor) – The input tensor.
dim (int) – index before which to insert the singleton dimension. A negative dimension will be converted to
dim = dim + input.rank + 1.
- Returns:
A new tensor.
- Return type:
- INPUT REQUIREMENTS:
input.dtypeis one of [float32,float16,bfloat16,int8,int32,int64,bool]- OUTPUT GUARANTEES:
return[0].dtype==input.dtype
Example
1input = tp.iota((2, 2), dtype=tp.float32) 2output = tp.unsqueeze(input, 1)
Local Variables¶>>> input tensor( [[0, 0], [1, 1]], dtype=float32, loc=gpu:0, shape=(2, 2)) >>> output tensor( [[[0, 0]], [[1, 1]]], dtype=float32, loc=gpu:0, shape=(2, 1, 2))