简体   繁体   中英

How do you implement ECDF in Python?

I'm trying to implement the empirical distribution function from a paper that has the MATLAB implementation on page 3. Here's my Python version of it.

I converted it according to the NumPy for MATLAB users documentation while taking into account how statsmodels implements ECDF

from statsmodels.distributions.empirical_distribution import ECDF     

def ecdf_representation(D, n):
     """calculate ECDF from D at n points"""
     m = np.mean(D)
     X = []
     for d in xrange(D.shape[0] + 1):
         func = ECDF([D[:, d] + np.random.randn(np.shape(D[:, d])) * 0.01])
         ll = func(np.linspace(0, 1, n))
         X = [X, ll]
     X = [X, m]
     plt.plot(X)
     plt.show()
     return X

I get the error:

line 25, in ecdf_representation
func = ECDF([D[:, d] + np.random.randn(np.shape(D[:, d]))])
IndexError: too many indices for array

Doesn't D.shape[0] return the number of columns? So, D[:, d] should work right? What's going on here?

D.shape[0] will return rows, not columns:

What does .shape[] do in "for i in range(Y.shape[0])"?

D.shape[1] will return columns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM