Hi Robert, > It's not quite an overflow. > > In [1]: from numpy import * > > In [2]: x = float32(16777216.0) > > In [3]: x + float32(0.9) > Out[3]: 16777216.0 > > You are accumulating your result in a float32. With the a.sum() > approach, you eventually hit a level where the next number to add is > always less than the relative epsilon of float32 precision. So the > result doesn't change. And will never change again as long as you only > add one number at a time. Summing along the other axes creates smaller > intermediate sums such that you are usually adding together numbers > roughly in the same regime as each other, so you don't lose as much > precision.
Thank you very much for that explanation; that completely makes sense. > > Use a.sum(dtype=np.float64) to use a float64 accumulator. > I didn't know about the dtype for accumulators/operators -- that did just the trick. Much obliged, Matt _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
