fn

pad

Tensor
pad(input: Tensor, padding: Sequence[int], mode: str = ..., value: float = ...)
source

Pad a tensor with the specified border widths.

padding lists (left, right) pairs starting from the last dimension and proceeding outward — the same convention used by the reference framework. The mode selects how new elements are filled.

Parameters

inputTensor
Source tensor.
paddingsequence of int
Border widths, in last-axis-first order.
modestr= ``'constant'``
One of 'constant', 'reflect', 'replicate', 'circular'.
valuefloat= 0.0
Fill value used by mode='constant'.

Returns

Tensor

Padded tensor.

Notes

Padding mode semantics:

  • constant — fill with value;
  • reflect — mirror without repeating the edge element;
  • replicate — repeat the edge element;
  • circular — wrap around.

Examples

>>> import lucid
>>> x = lucid.tensor([[1, 2], [3, 4]])
>>> lucid.pad(x, [1, 1, 0, 0], mode='constant', value=0)
Tensor([[0, 1, 2, 0],
        [0, 3, 4, 0]])