All problems
Conv Output Dimension
Problem
Compute the spatial output size of a convolution: floor((n + 2 * padding - dilation * (k - 1) - 1) / stride) + 1.
The signature is conv_output_dim(n, k, stride=1, padding=0, dilation=1). Return an integer.
Hint
Use integer division for the floor, and remember dilation widens the effective kernel.
Test cases
case 1
in: [28,3]
expected: 26
case 2
in: [28,3,2,1]
expected: 14
case 3
in: [32,5,1,2]
expected: 32
case 4
in: [7,3,1,0,2]
expected: 3
case 5
in: [10,3,3,0]
expected: 3
Starter codePython
def conv_output_dim(n, k, stride=1, padding=0, dilation=1):
# Your code here
pass5 test cases · run your code against them in the editor