Statistics module of Python 3.8 provides a function fmean() that converts all the data into float data-type and then computes the arithmetic mean or average of data that is provided in the form of a sequence or an iterable. The output of this function is always a float.
The only difference in computing mean using mean() and fmean() is that while using fmean() data gets converted to floats whereas in case of mean(), data does not get converted to floats. Moreover fmean() function runs faster than the mean() function.
Parameters:[data-set]: List or tuple of a set of numbers.
Returns: floating-point arithmetic mean of the provided data.
Exceptions: StatisticsError. Is raised when the data set is empty
Code #1: Demonstration of fmean()
Floating Point Mean is: 4.914285714285714
Code #2: Demonstration of fmean()
Floating Point Mean of A1 is 6.2 Floating Point Mean of A2 is -7.8999999999999995 Floating Point Mean of A3 is -0.41666666666666674 Floating Point Mean of A4 is 2.3000000000000003
Code #3: StatisticsError
Traceback (most recent call last):
File “”, line 1, in
py”, line 345, in fmean
raise StatisticsError(‘fmean requires at least one data point’) from None
statistics.StatisticsError: fmean requires at least one data point
The applications of fmean() is similar to mean(), although fmean() is relatively faster than mean(). fmean() is only to be used when the floating-point mean of data needs to be calculated, otherwise for calculating the mean of a sample, mean() is preferred. Since fmean() converts its data into floats, it produces more accurate results.
- Python statistics | mean() function
- Python statistics | mode function
- Python statistics | pvariance()
- Python statistics | harmonic_mean()
- Python statistics | median_grouped()
- Python statistics | stdev()
- Python statistics | variance()
- floor() and ceil() function Python
- ord() function in Python
- sum() function in Python
- round() function in Python
- id() function in Python
- vars() function in Python
- Intersection() function Python
- Union() function in Python
- Python | Permutation of a given string using inbuilt function
- Python | cmp() function
- Python math function | sqrt()
- Python math function | modf()
- Python list function | count()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.