summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authormelissawm <melissawm@gmail.com>2022-08-12 19:00:22 -0300
committermelissawm <melissawm@gmail.com>2022-08-12 19:07:23 -0300
commita52aae6793fbcea04148ca41456a3fe24b26efee (patch)
tree1d78957b58f643e3a1254e9a401696a4114c88f4 /numpy/lib/function_base.py
parent29b99f544a551d3590910bf8f398686336515ce4 (diff)
downloadnumpy-a52aae6793fbcea04148ca41456a3fe24b26efee.tar.gz
DOC: Fix documentation for percentile and quantile
Co-authored-by: deego <deego3@gmail.com>
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py57
1 files changed, 35 insertions, 22 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index fb5dd6fdd..af890183e 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -3979,7 +3979,7 @@ def percentile(a,
Notes
-----
- Given a vector ``V`` of length ``N``, the q-th percentile of ``V`` is
+ Given a vector ``V`` of length ``n``, the q-th percentile of ``V`` is
the value ``q/100`` of the way from the minimum to the maximum in a
sorted copy of ``V``. The values and distances of the two nearest
neighbors as well as the `method` parameter will determine the
@@ -3988,19 +3988,22 @@ def percentile(a,
same as the minimum if ``q=0`` and the same as the maximum if
``q=100``.
- This optional `method` parameter specifies the method to use when the
- desired quantile lies between two data points ``i < j``.
- If ``g`` is the fractional part of the index surrounded by ``i`` and
- alpha and beta are correction constants modifying i and j.
-
- Below, 'q' is the quantile value, 'n' is the sample size and
- alpha and beta are constants.
- The following formula gives an interpolation "i + g" of where the quantile
- would be in the sorted sample.
- With 'i' being the floor and 'g' the fractional part of the result.
+ The optional `method` parameter specifies the method to use when the
+ desired percentile lies between two indexes ``i`` and ``j = i + 1``.
+ In that case, we first determine ``i + g``, a virtual index that lies
+ between ``i`` and ``j``, where ``i`` is the floor and ``g`` is the
+ fractional part of the index. The final result is, then, an interpolation
+ of ``a[i]`` and ``a[j]`` based on ``g``. During the computation of ``g``,
+ ``i`` and ``j`` are modified using correction constants ``alpha`` and
+ ``beta`` whose choices depend on the ``method`` used. Finally, note that
+ since Python uses 0-based indexing, the code subtracts another 1 from the
+ index internally.
+
+ The following formula determines the virtual index ``i + g``, the location
+ of the percentile in the sorted sample:
.. math::
- i + g = q * ( n - alpha - beta + 1 ) + alpha
+ i + g = (q / 100) * ( n - alpha - beta + 1 ) + alpha
The different methods then work as follows
@@ -4265,18 +4268,28 @@ def quantile(a,
Notes
-----
- Given a vector ``V`` of length ``N``, the q-th quantile of ``V`` is the
- value ``q`` of the way from the minimum to the maximum in a sorted copy of
- ``V``. The values and distances of the two nearest neighbors as well as the
- `method` parameter will determine the quantile if the normalized
- ranking does not match the location of ``q`` exactly. This function is the
- same as the median if ``q=0.5``, the same as the minimum if ``q=0.0`` and
- the same as the maximum if ``q=1.0``.
+ Given a vector ``V`` of length ``n``, the q-th quantile of ``V`` is
+ the value ``q`` of the way from the minimum to the maximum in a
+ sorted copy of ``V``. The values and distances of the two nearest
+ neighbors as well as the `method` parameter will determine the
+ quantile if the normalized ranking does not match the location of
+ ``q`` exactly. This function is the same as the median if ``q=0.5``, the
+ same as the minimum if ``q=0.0`` and the same as the maximum if
+ ``q=1.0``.
The optional `method` parameter specifies the method to use when the
- desired quantile lies between two data points ``i < j``.
- If ``g`` is the fractional part of the index surrounded by ``i`` and ``j``,
- and alpha and beta are correction constants modifying i and j:
+ desired quantile lies between two indexes ``i`` and ``j = i + 1``.
+ In that case, we first determine ``i + g``, a virtual index that lies
+ between ``i`` and ``j``, where ``i`` is the floor and ``g`` is the
+ fractional part of the index. The final result is, then, an interpolation
+ of ``a[i]`` and ``a[j]`` based on ``g``. During the computation of ``g``,
+ ``i`` and ``j`` are modified using correction constants ``alpha`` and
+ ``beta`` whose choices depend on the ``method`` used. Finally, note that
+ since Python uses 0-based indexing, the code subtracts another 1 from the
+ index internally.
+
+ The following formula determines the virtual index ``i + g``, the location
+ of the quantile in the sorted sample:
.. math::
i + g = q * ( n - alpha - beta + 1 ) + alpha