fmean() function in Python statistics
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.