def ecdf_formal(x, data):
"""
Compute the values of the formal ECDF generated from `data` at x.
I.e., if F is the ECDF, return F(x).
Parameters
----------
x : int, float, or array_like
Positions at which the formal ECDF is to be evaluated.
data : array_like
One-dimensional array of data to use to generate the ECDF.
Returns
-------
output : float or ndarray
Value of the ECDF at `x`.
"""
# Remember if the input was scalar
if np.isscalar(x):
return_scalar = True
else:
return_scalar = False
# If x has any nans, raise a RuntimeError
if np.isnan(x).any():
raise RuntimeError('Input cannot have NaNs.')
# Convert x to array
x = _convert_data(x, inf_ok=True)
# Convert data to sorted NumPy array with no nan's
data = _convert_data(data, inf_ok=True)
# Compute formal ECDF value
out = _ecdf_formal(x, np.sort(data))
if return_scalar:
return out[0]
return out
评论列表
文章目录