def quantile(x, q, interpolation_method='<STR_LIT>'):
x = np.asarray(x)<EOL>mask = isna(x)<EOL>x = x[~mask]<EOL>values = np.sort(x)<EOL>def _interpolate(a, b, fraction):<EOL><INDENT>"""<STR_LIT>"""<EOL>return a + (b - a) * fraction<EOL><DEDENT>def _get_score(at):<EOL><INDENT>if len(values) == <NUM_LIT:0>:<EOL><INDENT>return np.nan<EOL><DEDENT>idx = at * (len(values) - <NUM_LIT:1>)<EOL>if idx % <NUM_LIT:1> == <NUM_LIT:0>:<EOL><INDENT>score = values[int(idx)]<EOL><DEDENT>else:<EOL><INDENT>if interpolation_method == '<STR_LIT>':<EOL><INDENT>score = _interpolate(values[int(idx)], values[int(idx) + <NUM_LIT:1>],<EOL>idx % <NUM_LIT:1>)<EOL><DEDENT>elif interpolation_method == '<STR_LIT>':<EOL><INDENT>score = values[np.floor(idx)]<EOL><DEDENT>elif interpolation_method == '<STR_LIT>':<EOL><INDENT>score = values[np.ceil(idx)]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>return score<EOL><DEDENT>if is_scalar(q):<EOL><INDENT>return _get_score(q)<EOL><DEDENT>else:<EOL><INDENT>q = np.asarray(q, np.float64)<EOL>return algos.arrmap_float64(q, _get_score)<EOL><DEDENT>
Compute sample quantile or quantiles of the input array. For example, q=0.5
computes the median.

The `interpolation_method` parameter supports three values, namely
`fraction` (default), `lower` and `higher`. Interpolation is done only,
if the desired quantile lies between two data points `i` and `j`. For
`fraction`, the result is an interpolated value between `i` and `j`;
for `lower`, the result is `i`, for `higher` the result is `j`.

Parameters
----------
x : ndarray
    Values from which to extract score.
q : scalar or array
    Percentile at which to extract score.
interpolation_method : {'fraction', 'lower', 'higher'}, optional
    This optional parameter specifies the interpolation method to use,
    when the desired quantile lies between two data points `i` and `j`:

    - fraction: `i + (j - i)*fraction`, where `fraction` is the
                fractional part of the index surrounded by `i` and `j`.
    -lower: `i`.
    - higher: `j`.

Returns
-------
score : float
    Score at percentile.

Examples
--------
>>> from scipy import stats
>>> a = np.arange(100)
>>> stats.scoreatpercentile(a, 50)
49.5