def prctile(x, p = (0.0, 25.0, 50.0, 75.0, 100.0)): """ Return the percentiles of x. p can either be a sequence of percentil values or a scalar. If p is a sequence the i-th element of the return sequence is the p(i)-th percentile of x """ x = sort(ravel(x)) Nx = len(x) if not iterable(p): return x[int(p*Nx/100.0)] p = multiply(array(p), Nx/100.0) ind = p.astype(Int) ind = where(ind>=Nx, Nx-1, ind) return take(x, ind)
def prctile(x, p=(0.0, 25.0, 50.0, 75.0, 100.0)): """ Return the percentiles of x. p can either be a sequence of percentil values or a scalar. If p is a sequence the i-th element of the return sequence is the p(i)-th percentile of x """ x = sort(ravel(x)) Nx = len(x) if not iterable(p): return x[int(p * Nx / 100.0)] p = multiply(array(p), Nx / 100.0) ind = p.astype(Int) ind = where(ind >= Nx, Nx - 1, ind) return take(x, ind)