Skip to content

numpy.mean(): accumulator default type should not be single precision (Trac #435) #1033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 1 comment

Comments

@numpy-gitbot
Copy link

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.

@numpy-gitbot
Copy link
Author

@chanley wrote on 2007-03-23

Closing this ticket since it is a duplicate of #1063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant