expand¶
- tripy.expand(input: Tensor, sizes: Sequence[int | DimensionSize]) Tensor [source]¶
Returns a new tensor based on the input tensor with singleton dimensions expanded to a larger size.
- Parameters:
input (Tensor) – [dtype=T1] The input tensor.
sizes (Sequence[int | DimensionSize]) – The desired expanded size. A value of \(-1\) indicates that the dimension should not be modified. If the length of this parameter exceeds the rank of the tensor, new dimensions are prepended.
- Returns:
[dtype=T1] The new tensor.
- Return type:
Example
1input = tp.iota((2, 1), dtype=tp.float32) 2output = tp.expand(input, (-1, 4))
>>> input tensor( [[0.0000], [1.0000]], dtype=float32, loc=gpu:0, shape=(2, 1)) >>> output tensor( [[0.0000, 0.0000, 0.0000, 0.0000], [1.0000, 1.0000, 1.0000, 1.0000]], dtype=float32, loc=gpu:0, shape=(2, 4))
Example: Increasing Tensor Rank
1input = tp.iota((1, 1), dtype=tp.float32) 2output = tp.expand(input, (3, -1, -1))
>>> input tensor([[0.0000]], dtype=float32, loc=gpu:0, shape=(1, 1)) >>> output tensor( [[[0.0000]], [[0.0000]], [[0.0000]]], dtype=float32, loc=gpu:0, shape=(3, 1, 1))