pad
- arrayfire.pad(array: Array, start_shape: tuple[int, ...], end_shape: tuple[int, ...], /, *, fill_type: Pad = Pad.ZERO) Array
Pads an ArrayFire array with specified sizes of padding around its edges and fills the padding with a specified value.
This function allows for the padding of an array on all sides with a variety of filling options for the new elements added by the padding process. The amount of padding to add at the start and end of each dimension is specified by start_shape and end_shape, respectively.
Parameters
- arrayArray
The input multi-dimensional ArrayFire array to be padded.
- start_shapetuple[int, …]
The amount of padding to add at the beginning of each dimension of the array. Each value in the tuple corresponds to a dimension in the array.
- end_shapetuple[int, …]
The amount of padding to add at the end of each dimension of the array. Each value in the tuple corresponds to a dimension in the array.
- fill_typePad, optional, keyword-only, default: Pad.ZERO
The type of value to fill the padded areas with. The default is Pad.ZERO, which fills the padded area with zeros. Other options may include constant values or methods of padding such as edge value replication, depending on the library’s implementation.
Returns
- Array
The padded ArrayFire array. The shape of the output array will be larger than the input array by the amounts specified in start_shape and end_shape.
Examples
>>> import arrayfire as af >>> a = af.randu((3, 3)) >>> a [3 3 1 1] 0.4107 0.1794 0.3775 0.8224 0.4198 0.3027 0.9518 0.0081 0.6456
>>> af.pad(a, (1, 1), (1, 1)) [5 5 1 1] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.4107 0.1794 0.3775 0.0000 0.0000 0.8224 0.4198 0.3027 0.0000 0.0000 0.9518 0.0081 0.6456 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000