gini
gini copied to clipboard
Update gini.py
import numpy as np test_list = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000] np_array_test_list = np.array(test_list)
i use this as a test array, add it throw out an error,
`UFuncTypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_10648\1272286076.py in
~\AppData\Local\Temp\ipykernel_10648\4044443746.py in gini4(array) 6 if np.amin(array) < 0: 7 array -= np.amin(array) #values cannot be negative ----> 8 array += 0.0000001 #values cannot be 0 9 array = np.sort(array) #values must be sorted 10 index = np.arange(1,array.shape[0]+1) #index per array element
UFuncTypeError: Cannot cast ufunc 'add' output from dtype('float64') to dtype('int32') with casting rule 'same_kind'`
but if i add array = array.astype(float)
, the error disappered.