Skip to content

Instantly share code, notes, and snippets.

@rsokl
Last active April 6, 2022 16:16
Show Gist options
  • Save rsokl/f882e74ef16cdd22a9e12ac438f8ff50 to your computer and use it in GitHub Desktop.
Save rsokl/f882e74ef16cdd22a9e12ac438f8ff50 to your computer and use it in GitHub Desktop.
ecdf : empirical cumulative distribution function
import numpy as np
def ecdf(data):
"""Returns (x) the sorted data and (y) the empirical cumulative-proportion
of each datum.
Parameters
----------
data : numpy.ndarray, size-N
Returns
-------
Tuple[numpy.ndarray shape-(N,), numpy.ndarray shape-(N,)]
Sorted data, empirical CDF values"""
data = np.asarray(data).ravel()
y = np.linspace(1 / len(data), 1, len(data))
x = np.sort(data)
return x, y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment