pad¶
- tripy.pad(input: Tensor, pad: Sequence[Sequence[int | DimensionSize]], mode: str = 'constant', value: int | float = 0) Tensor [source]¶
Pads the input tensor.
- Parameters:
input (Tensor) – The input tensor.
pad (Sequence[Sequence[int | DimensionSize]]) – A sequence of padding sizes of each dimension. Its length must be equal to the rank of
input
. Each element ofpad
is a tuple of integers orDimensionSize
s(low, high)
, which represents the padding sizes before the lowest index and after the highest index at the corresponding dimension.mode (str) – The padding mode. Only “constant” is supported.
value (int | float) – The padding value for “constant” mode.
- Returns:
The padded tensor.
- Return type:
Example: Constant padding.
1input = tp.reshape(tp.arange(6, dtype=tp.float32), (2, 3)) 2output = tp.pad(input, ((1, 0), (0, 1)))
>>> input tensor( [[0.0000, 1.0000, 2.0000], [3.0000, 4.0000, 5.0000]], dtype=float32, loc=gpu:0, shape=(2, 3)) >>> output tensor( [[0.0000, 0.0000, 0.0000, 0.0000], [0.0000, 1.0000, 2.0000, 0.0000], [3.0000, 4.0000, 5.0000, 0.0000]], dtype=float32, loc=gpu:0, shape=(3, 4))