![]() |
VOOZH | about |
numpy.percentile() compute the q-th percentile of data along the specified axis. A percentile is a measure indicating the value below which a given percentage of observations in a group falls. Example:
5.0
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, interpolation='linear', keepdims=False, method='linear')
Parameters:
Parameter | Description |
|---|---|
a | Input array or object that can be converted to an array |
q | Percentile(s) to compute (0–100). Can be scalar or array-like |
axis | Axis along which the percentiles are computed. Default is None (flattened) |
out | Optional output array |
overwrite_input | If True, the input array can be modified for memory efficiency |
interpolation | (Deprecated) Use method instead |
method | Method to compute percentile: 'linear', 'lower', 'higher', 'midpoint', 'nearest' |
keepdims | If True, the reduced axes are left in the result as dimensions with size one |
Returns: The q-th percentile(s) of the array elements. If q is a list, it returns multiple percentiles.
Example 1: In this example, we compute the 25th, 50th and 75th percentiles of a 1D array.
[20. 30. 40.]
Example 2: In this example, we compute the 50th percentile (median) along each row of a 2D array using the axis parameter.
[7. 2.]
Example 3: In this example, we compute the 50th percentile (median) using the method='lower' option.
2
Example 4: In this example, we compute the 50th percentile (median) along each row of a 2D array and use keepdims=True to preserve the original dimensions.
[[20.] [50.]]