#129Convolution — one patch stepEasyCNNComputer Vision
Convolution — one patch step
Background
A convolution is a small recipe repeated at every position: take a patch of the image, multiply it element-wise by the filter, sum, and add a bias. That single number becomes one entry of the feature map.
Problem statement
Implement conv_step(patch, kernel, bias) computing one output value: the element-wise product summed, plus bias.
Input
patch— array-like, a region of the image (same shape askernel).kernel— array-like filter weights.bias—float.
Output
Returns a Python float: .
Examples
Example 1
Input: patch = [[1, 2], [3, 4]], kernel = [[1, 0], [0, 1]], bias = 0
Output: 5.0
Explanation: .
Example 2 — with a bias
Input: patch = [[1, 1, 1]], kernel = [[1, 1, 1]], bias = 2
Output: 5.0
Explanation: .
Constraints
- Element-wise multiply, sum all entries, add
bias. - Return a plain
float.
Notes
- The (non-linear) activation usually applied after this — e.g. ReLU — is the final step of a full conv layer; here you compute the pre-activation.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example — identity-ish kernel
- •Reference — sum kernel with bias
- •Sample — negative weights cancel