Recommand · October 16, 2021 0

Empirical distribution function in python

I want to calculate empirical distribution in python – this is my current code –

def Empirical_F(X):
    x = np.sort(X)
    y = np.arange(1, len(x) + 1) / float(len(x))
    return np.column_stack((x, y))

but my result for the vector 8, 2, -13, 4, -9, 0, 18, 4, -5, 10, 1, -7, 7, 13, -5, -16, -9, 18, -10, 0]

is as follows –

 [[-16.     0.05]
 [-13.     0.1 ]
 [-10.     0.15]
 [ -9.     0.2 ]
 [ -9.     0.25]
 [ -7.     0.3 ]
 [ -5.     0.35]
 [ -5.     0.4 ]
 [  0.     0.45]
 [  0.     0.5 ]
 [  1.     0.55]
 [  2.     0.6 ]
 [  4.     0.65]
 [  4.     0.7 ]
 [  7.     0.75]
 [  8.     0.8 ]
 [ 10.     0.85]
 [ 13.     0.9 ]
 [ 18.     0.95]
 [ 18.     1.  ]]

I want to fix that when x value is the same so does y value
I want them to have the same value.

Thanks!