summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-02-21 23:06:29 (GMT)
committerGitHub <noreply@github.com>2019-02-21 23:06:29 (GMT)
commit47d9987247bcc45983a6d51fd1ae46d5d356d0f8 (patch)
tree16b7e88590f9a28ff47e8a0e041510c4a2d86756 /Doc/library
parentf36f89257b30e0bf88e8aaff6da14a9a96f57b9e (diff)
downloadcpython-47d9987247bcc45983a6d51fd1ae46d5d356d0f8.zip
cpython-47d9987247bcc45983a6d51fd1ae46d5d356d0f8.tar.gz
cpython-47d9987247bcc45983a6d51fd1ae46d5d356d0f8.tar.bz2
bpo-35904: Add statistics.fmean() (GH-11892)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/random.rst4
-rw-r--r--Doc/library/statistics.rst18
2 files changed, 20 insertions, 2 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 7d051e1..79a7bdd 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -404,7 +404,7 @@ with replacement to estimate a confidence interval for the mean of a sample of
size five::
# http://statistics.about.com/od/Applications/a/Example-Of-Bootstrapping.htm
- from statistics import mean
+ from statistics import fmean as mean
from random import choices
data = 1, 2, 4, 4, 10
@@ -419,7 +419,7 @@ to determine the statistical significance or `p-value
between the effects of a drug versus a placebo::
# Example from "Statistics is Easy" by Dennis Shasha and Manda Wilson
- from statistics import mean
+ from statistics import fmean as mean
from random import shuffle
drug = [54, 73, 53, 70, 73, 68, 52, 65, 65]
diff --git a/Doc/library/statistics.rst b/Doc/library/statistics.rst
index 26bb592..20a2c1c 100644
--- a/Doc/library/statistics.rst
+++ b/Doc/library/statistics.rst
@@ -39,6 +39,7 @@ or sample.
======================= =============================================
:func:`mean` Arithmetic mean ("average") of data.
+:func:`fmean` Fast, floating point arithmetic mean.
:func:`harmonic_mean` Harmonic mean of data.
:func:`median` Median (middle value) of data.
:func:`median_low` Low median of data.
@@ -111,6 +112,23 @@ However, for reading convenience, most of the examples show sorted sequences.
``mean(data)`` is equivalent to calculating the true population mean μ.
+.. function:: fmean(data)
+
+ Convert *data* to floats and compute the arithmetic mean.
+
+ This runs faster than the :func:`mean` function and it always returns a
+ :class:`float`. The result is highly accurate but not as perfect as
+ :func:`mean`. If the input dataset is empty, raises a
+ :exc:`StatisticsError`.
+
+ .. doctest::
+
+ >>> fmean([3.5, 4.0, 5.25])
+ 4.25
+
+ .. versionadded:: 3.8
+
+
.. function:: harmonic_mean(data)
Return the harmonic mean of *data*, a sequence or iterator of