我试图从第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]
应该正常吗?这里发生了什么?
答案 0 :(得分:1)