I usually work with huge simulations. Sometimes, I need to compute the center of mass of the set of particles. I noted that in many situations, the mean value returned by numpy.mean()
is wrong. I can figure out that it is due to a saturation of the accumulator. In order to avoid the problem, I can split the summation over all particles in small set of particles, but it is uncomfortable. Anybody has and idea of how to solve this problem in an elegant way?
Just for piking up your curiosity, the following example produce something similar to what I observe in my simulations:
import numpy as np
a = np.ones((1024,1024), dtype=np.float32)*30504.00005
If you check the .max
and .min
values, you get:
a.max()
=> 30504.0
a.min()
=> 30504.0
However, the mean value is:
a.mean()
=> 30687.236328125
You can figure out that something is wrong here. This is not happening when using dtype=np.float64
, so it should be nice to solve the problem for single precision.