pad¶
- nvtripy.pad(input: Tensor, pad: Sequence[Tuple[int | DimensionSize, int | DimensionSize]], mode: str = 'constant', value: int | float = 0) Tensor [source]¶
Pads the input tensor.
- Parameters:
input (Tensor) – [dtype=T1] The input tensor.
pad (Sequence[Tuple[int | DimensionSize, 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:
[dtype=T1] 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)])
Local Variables¶>>> input tensor( [[0, 1, 2], [3, 4, 5]], dtype=float32, loc=gpu:0, shape=(2, 3)) >>> output tensor( [[0, 0, 0, 0], [0, 1, 2, 0], [3, 4, 5, 0]], dtype=float32, loc=gpu:0, shape=(3, 4))