Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-101

Chi-Square Histogram Distance

Problem

Compute the chi-square distance between two histograms.

Sum (a - b)^2 / (a + b) over all bins, skipping bins where a + b is 0, and round to 4 decimal places.

Test cases

case 1
in: [[1,2],[2,1]]
expected: 0.6667
case 2
in: [[1,2],[1,2]]
expected: 0
case 3
in: [[0,0],[0,0]]
expected: 0
case 4
in: [[4,0],[0,4]]
expected: 8
Starter codePython
def chi_square_distance(h1, h2):
    # Your code here
    pass

4 test cases · run your code against them in the editor