numpy.mean() in Python
The sum of elements, along with an axis divided by the number of elements, is known as arithmetic mean. The numpy.mean() function is used to compute the arithmetic mean along the specified axis.
This function returns the average of the array elements. By default, the average is taken on the flattened array. Else on the specified axis, float 64 is intermediate as well as return values are used for integer inputs
These are the following parameters in numpy.mean() function:
This parameter defines the source array containing elements whose mean is desired. In such a case where 'a' is not an array, a conversion is attempted.
axis: None, int or tuple of ints(optional)
This parameter defines the axis along which the means are computed. By default, the mean is computed of the flattened array. In version 1.7.0, if this is a tuple of ints, the mean is performed over multiple axes, instead of a single axis or all the axes as before.
This parameter is used to define the data-type used in computing the mean. For integer inputs, the default is float64, and for floating-point inputs, it is the same as the input dtype.
This parameter defines an alternative output array in which the result will be placed. The shape of the resulting array should be the same as the shape of the expected output. The type of output values will cast when necessary.
When the value is true, the reduced axis is left as dimensions with size one in the output/result. Also, the result broadcasts correctly against the input array. When the default value is set, the keepdims does not pass via the mean method of sub-classes of ndarray, but any non-default value will surely pass. In case the sub-class method does not implement keepdims, then an exception will surely rise.
If we set the 'out' parameter to None, this function returns a new array containing the mean values. Otherwise, it will return the reference to the output array.
In the above code
array([2.5, 4.5]) array([3., 4.])
In single precision, mean can be inaccurate:
In the above code
In the output, it shows the mean of array 'a'.
Computing the mean in float64 is more accurate: