tidy3d.plugins.autograd.functions.pad#
- class pad[source]#
Bases:
Pad an array along a specified axis with a given mode and padding width.
- Parameters:
array (NDArray) β The input array to pad.
pad_width (Union[int, Tuple[int, int]]) β The number of values padded to the edges of each axis. If an integer is provided, it is used for both the left and right sides. If a tuple is provided, it specifies the padding for the left and right sides respectively.
mode (PaddingType = "constant") β The padding mode to use.
axis (Union[int, Iterable[int], None] = None) β The axis or axes along which to pad. If None, padding is applied to all axes.
constant_value (float = 0.0) β The value to set the padded values for βconstantβ mode.
- Returns:
The padded array.
- Return type:
NDArray
- Raises:
ValueError β If the padding width has more than two elements or if padding is negative.
NotImplementedError β If padding larger than the input size is requested.
KeyError β If an unsupported padding mode is specified.
IndexError β If an axis is out of range for the array dimensions.
Examples
>>> import numpy as np >>> from tidy3d.plugins.autograd.functions import pad >>> array = np.array([[1, 2], [3, 4]]) >>> pad(array, (1, 1), mode="constant", constant_value=0) array([[0, 0, 0, 0], [0, 1, 2, 0], [0, 3, 4, 0], [0, 0, 0, 0]]) >>> pad(array, 1, mode="reflect") array([[4, 3, 4, 3], [2, 1, 2, 1], [4, 3, 4, 3], [2, 1, 2, 1]])
Inherited Common Usage