Closed
Description
Original ticket http://projects.scipy.org/numpy/ticket/435 on 2007-01-24 by @chanley, assigned to unknown.
The accumulator used in the mean algorithm should not be single precision by default. This default can cause unexpected results. Please see the following example:
In [5]: a.dtype
Out[5]: dtype('>f4')
In [6]: print a
[[ 132. 132. 132. ..., 132. 132. 132.]
[ 132. 132. 132. ..., 132. 132. 132.]
[ 132. 132. 132. ..., 132. 132. 132.]
...,
[ 132. 132. 132. ..., 132. 132. 132.]
[ 132. 132. 132. ..., 132. 132. 132.]
[ 132. 132. 132. ..., 132. 132. 132.]]
In [7]: a.min()
Out[7]: 132.0
In [8]: a.max()
Out[8]: 389.0
In [9]: a.mean()
Out[9]: 129.742439153
However, if you recast the array as float64 you get the correct result:
In [11]: a.astype(numpy.float64).mean()
Out[11]: 132.062805059
I believe that double precision would be a more appropriate default type for the accumulator.