Code

Two-Dimensional Cross-Correlation Code Implementation

The two-dimensional cross-correlation operation can be implemented programmatically by iterating over the valid spatial positions of the output tensor. For an input tensor X and a kernel tensor K, the output dimensions are first initialized based on the formula (nhkh+1)×(nwkw+1)(n_\textrm{h}-k_\textrm{h}+1) \times (n_\textrm{w}-k_\textrm{w}+1). A nested loop then systematically slides the kernel across the input, performing an elementwise multiplication and summation for each local window to yield the final output tensor.

0

1

Updated 2026-05-12

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L