Katkat

Implement and vectorize NumPy Conv2D

TeslaMachine Learning Engineer · Technical Screen

Last updated

This question evaluates understanding of 2D convolution mechanics, multidimensional NumPy array manipulation, and the competency to optimize numerical computations for performance and memory.

Implement a 2D convolution operation from scratch using NumPy only (no TensorFlow or PyTorch). Assume NCHW input shape (N, C_in, H_in, W_in) and weights of shape (C_out, C_in, k_h, k_w); support configurable stride and padding. First provide a clear nested-loop reference implementation; then optimize by vectorizing the computation (e.g., im2col or stride tricks) and discuss time/memory trade-offs.