【发布时间】:2017-12-04 11:41:38
【问题描述】:
我正在尝试从具有第 3 页上的 MATLAB 实现的 paper 实现经验分布函数。这是我的 Python 版本。
我根据NumPy for MATLAB users documentation进行转换,同时考虑到statsmodelsimplementsECDF的方式
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] 应该可以正常工作吗?这是怎么回事?
【问题讨论】:
标签: python matlab statsmodels ecdf index-error