def ecdf(x):
"""Empirical cumulative distribution function
Given a 1D array of values, returns a function f(q) that outputs the
fraction of values less than or equal to q.
Parameters
----------
x : 1D array
values for which to compute CDF
Returns
----------
ecdf_fun: Callable[[float], float]
function that returns the value of the CDF at a given point
"""
xp = np.sort(x)
yp = np.arange(len(xp) + 1) / len(xp)
def ecdf_fun(q):
return yp[np.searchsorted(xp, q, side="right")]
return ecdf_fun
评论列表
文章目录