[Tutor] numerical problem

Steven D'Aprano steve at pearwood.info
Tue Mar 4 03:02:02 CET 2014


On Mon, Mar 03, 2014 at 08:00:52PM -0500, Gabriele Brambilla wrote:
> Hi,
> 
> I'm doing a sum in a for loop:
> 
> www is the quantity I add.
> 
> MYMAP[i, j, k] = MYMAP[i, j, k] + www
> 
> MYMAP is a numpy array
> 
> I have strong reasons to think that in this operation happens some
> numerical error...Have you suggestions to discover where it is?

You are almost certainly correct. Unless all the numbers are exact 
integers, nearly every floating point operation will add some error.

Without seeing your code, and some representative sample data, it is 
impossible to tell whether the error is tiny or huge.

Tiny error:

MYMAP[1, j, k] = 1.001
www = 0.25


Huge error:

MYMAP[1, j, k] = 1.001e19
www = 0.25



-- 
Steven


More information about the Tutor mailing list