你如何在Python中实现ECDF?

时间:2017-06-30 13:29:49

标签: python matlab statsmodels ecdf index-error

我试图从第3页上的MATLAB实现的paper实现经验分布函数。这是我的Python版本。

我根据NumPy for MATLAB users documentation转换了它,同时考虑了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

我收到错误:

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

不会D.shape[0]返回列数吗?那么,D[:, d]应该正常吗?这里发生了什么?

1 个答案:

答案 0 :(得分:1)

D.shape [0]将返回行,而不是列:

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

D.shape [1]将返回列