def theil(x, weights):
    assert numpy.all(x >= 0), "negative numbers can't be used in Theil"
    x_mean = numpy.average(x, weights=weights) + 1e-100
    normed = x / x_mean
    normed[normed < 1e-10] = 1e-10
    return numpy.average(normed * numpy.log(normed), weights=weights)
Theil index of array with regularization
dataset/ETHPy150Open anaderi/lhcb_trigger_ml/hep_ml/metrics_utils.py/theil