Conv2D Output Shape

~12 mincode completion

Implement conv2d_output_shape(input_h, input_w, filter_h, filter_w, stride) that returns a tuple (out_h, out_w).

Examples

7x7 input, 3x3 filter, stride 1 → 5x5

Input
conv2d_output_shape(7, 7, 3, 3, 1)
Output
[5, 5]

7x7 input, 3x3 filter, stride 2 → 3x3

Input
conv2d_output_shape(7, 7, 3, 3, 2)
Output
[3, 3]

Non-square input

Input
conv2d_output_shape(10, 6, 3, 3, 1)
Output
[8, 4]

Hints

Hint 1

Work directly with the arguments input_h, input_w, filter_h, filter_w, stride and return the result rather than printing it.

Hint 2

Do not forget to floor division. That step is easy to skip.

Requirements

  • input_h: Input height

  • input_w: Input width

  • filter_h: Filter height

  • filter_w: Filter width

  • stride: Stride (same in both dimensions)

  • Return Tuple (out_h, out_w) of output dimensions.

Constraints

  • Standard library only, no imports required

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

8 employers weight this skill

4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 92.

Python
def conv2d_output_shape(input_h: int, input_w: int, filter_h: int, filter_w: int, stride: int):
    """
    Compute the output spatial dimensions of a valid (no-padding) 2D convolution.

    Args:
        input_h:  Input height
        input_w:  Input width
        filter_h: Filter height
        filter_w: Filter width
        stride:   Stride (same in both dimensions)

    Returns:
        Tuple (out_h, out_w) of output dimensions.
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.