giagrad.Tensor.pad#
- Tensor.pad(*padding, mode: str = 'constant', **kwargs)[source]#
Pads tensor.
Padding size specified by
*padding
maps every argument starting from the rightmost axis. If*padding
is a single intN
it will be interpreted as if “before” and “after” padding for the last axis is symmetric, i.e.(N_before, N_after)
. If a tuple of two integers is supplied, it will be interpreted as(N_before, N_after)
padding.Padding
mode
has the same options as numpy.pad.See also
- Parameters:
Examples
>>> t = Tensor.empty(2, 2, 3, dtype=int).uniform(-5, 5) >>> t tensor: [[[ 0 -1 0] [ 0 2 0]] ... [[-1 -2 0] [-3 -1 3]]]
A single int padds the last axis with before and after symmetrically:
>>> t.pad(2) tensor: [[[ 0 0 0 -1 0 0 0] [ 0 0 0 2 0 0 0]] ... [[ 0 0 -1 -2 0 0 0] [ 0 0 -3 -1 3 0 0]]] fn: ConstantPad >>> t.pad((1, 0), 2, (1, 3)) tensor: [[[ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0]] ... [[ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 -1 0 0 0 0] [ 0 0 2 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0]] ... [[ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0] [ 0 -1 -2 0 0 0 0] [ 0 -3 -1 3 0 0 0] [ 0 0 0 0 0 0 0] [ 0 0 0 0 0 0 0]]] fn: ConstantPad