[Numpy-discussion] bug in numpy.mean() ?
Tue Jan 24 13:05:50 CST 2012
> You have a million 32-bit floating point numbers that are in the
> thousands. Thus you are exceeding the 32-bitfloat precision and, if you
> can, you need to increase precision of the accumulator in np.mean() or
> change the input dtype:
>>>> a.mean(dtype=np.float32) # default and lacks precision
> Otherwise you are left to using some alternative approach to calculate
> the mean.
Interesting -- I knew that float64 accumulators were used with integer arrays, and I had just assumed that 64-bit or higher accumulators would be used with floating-point arrays too, instead of the array's dtype. This is actually quite a bit of a gotcha for floating-point imaging-type tasks -- good to know!
More information about the NumPy-Discussion