def chisquared(points, data):
    # all values in the histogram must be positive
    assert points.min() >= 0.0
    assert data.min() >= 0.0
    
    _,c = data.shape
    
    
    dist_mat = []
    for pt in points:
        pt = pt.reshape(1,c)
        tmp1 = (data - pt)**2
        tmp2 = data + pt
        mask = tmp2 < 0.000001
        tmp3 = (tmp1 * ~mask) /(tmp2 + 1.0*mask) # prevent divide by zero
        
        row = np.sum(tmp3,axis=1)
        dist_mat.append(row)
    
    return np.array(dist_mat)
Compute the chi squared statistic between histograms
dataset/ETHPy150Open bolme/pyvision/src/pyvision/ml/knn.py/chisquared