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