Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Generate 2D Gaussian Blur Kernels

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Generate 2D Gaussian Blur Kernels. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Luma AI image pipelines use Gaussian blur kernels to smooth rendered frames before downstream processing. Implement gaussian_kernel(k, sigma) to return a normalized two-dimensional Gaussian kernel of size k x k.

Formal Specification

Given an odd positive integer k and a positive floating-point standard deviation sigma, center the kernel at coordinate (0, 0). For each offset (x, y), compute:

G(x, y) = exp(-(x² + y²) / (2 * sigma²))

Normalize every value by the sum of all unnormalized values so that the returned matrix sums to 1.0. Coordinates should range from -(k // 2) through k // 2 in both dimensions. Return a Python list containing k lists, each with k floats. Values are judged with a tolerance of 1e-9.

Constraints

  • 1 <= k <= 101
  • k is odd
  • 0 < sigma <= 100.0
  • Return exactly k rows, each containing k floating-point values
  • The sum of all returned values must be within 1e-9 of 1.0

Function Signature

def gaussian_kernel(k, sigma):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output