Zero padding
Zero padding extends an array or tensor beyond its boundary with elements equal to zero, often to control the output dimensions of a computation such as convolution.
Grokking GPU Programming
Zero padding extends an input with zero-valued elements beyond its boundary.
- How it is used
- Defines out-of-bounds values for stencil operations and fills partial CUDA matrix tiles to preserve correctness.
- How deep it goes
- Explains 1D and 2D boundary behavior and shows zero-filled tile loads, without detailing lower-level hardware behavior.
- Examples
- Uses a black border around image data, partial matrix tiles, and PyTorch conv2d with padding=1.
- What you can do after
- Apply zero-valued boundary reads in stencil kernels and use padding=1 for same-sized stride-1 convolution.
Math and Architectures of Deep Learning
A convolution setting that extends the input with zeros so the kernel can produce outputs near the boundary.
- How it is used
- Controls convolution boundaries and output dimensions when kernels approach the edges of input arrays.
- How deep it goes
- Derives padded input size and boundary positions, but stops short of implementation-specific padding configuration.
- Examples
- Uses a one-dimensional kernel of size three and a final window containing one input value followed by two zeros.
- What you can do after
- Apply it to reason about boundary outputs and calculate how padding changes the effective convolution input.
Read how Math and Architectures of Deep Learning explains zero padding →
Learn Generative AI with PyTorch
The addition of zero-valued borders around an input to control convolution output size.
- How it is used
- Controls convolution output dimensions while extracting spatial features in convolutional neural networks.
- How deep it goes
- Explains borders, output-size effects, tensor dimensions, and scan calculations, but does not derive general convolution formulas.
- Examples
- Uses a 3 × 3 input, a 2 × 2 filter, padding=1, stride=2, explicit scan arithmetic, and a 2 × 2 output tensor.
- What you can do after
- Apply it via nn.Conv2d by setting padding alongside kernel_size and stride to shape convolution outputs.
Read how Learn Generative AI with PyTorch explains zero padding →
Also covered in
What to know first
- inputAn input is information, a value, or an action supplied to a system, program, or computation for processing or to influence its behavior.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- convolutional layerA convolutional layer is a neural-network layer that applies shared learned filters to local regions of structured input to produce feature representations.
- dimensionA dimension is an independent coordinate or feature axis used to represent points or data; the dimensionality of a representation is the number of such axes or components.
Related concepts
- zero-pointuses · A quantization zero-point is the integer value that represents real zero in an affine mapping between real values and quantized integer values.
- inner productuses · An inner product is a scalar-valued operation on two vectors that generalizes the dot product, which for real coordinate vectors is the sum of products of corresponding components.
- dimensionaddresses · A dimension is an independent coordinate or feature axis used to represent points or data; the dimensionality of a representation is the number of such axes or components.
Questions about zero padding
What is zero padding?
Zero padding extends an array or tensor beyond its boundary with elements equal to zero, often to control the output dimensions of a computation such as convolution.
Which Manning books explain zero padding?
Grokking GPU Programming, Math and Architectures of Deep Learning and Learn Generative AI with PyTorch.
What should I know before learning zero padding?
Manning books that teach zero padding usually introduce input, array, convolutional layer and dimension first.
What is zero padding a kind of?
Zero padding is a kind of boundary condition. A boundary condition is a value, constraint, or behavior specified at the limit of a mathematical domain or system’s operating range.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


