# [Numpy-discussion] Numpy float precision vs Python list float issue

Rob Clewley rob.clewley@gmail....
Mon Apr 20 09:39:39 CDT 2009

```David,

you'd ever get non-zero error after the forward and inverse transform,
but why his implementation using lists gives zero error but using
arrays he gets something of order 1e-15.

On Mon, Apr 20, 2009 at 9:47 AM, David Cournapeau
<david@ar.media.kyoto-u.ac.jp> wrote:
>> I'm using Scipy/Numpy to do image wavelet transforms via the lifting
>> scheme. I grabbed some code implementing the transforms with Python
>> lists (float type). This code works perfectly, but slow for my needs
>> (I'll be doing some genetic algorithms to evolve coefficients of the
>> filters and the forward and inverse transform will be done many
>> times). It's just implemented by looping in the lists and making
>> computations this way. Reconstructed image after doing a forward and
>> inverse transform is perfect, this is, original and reconstructed
>> images difference is 0.
>>
>> With Scipy/Numpy float arrays slicing this code is much faster as you
>> know. But the reconstructed image is not perfect. The image difference
>> maximum and minimum values returns:
>> maximum difference => 3.5527136788e-15
>> minimum difference => -3.5527136788e-15
>>
>> Is this behavior expected?
>
> Yes, it is expected, it is inherent to how floating point works. By
> default, the precision for floating point array is double precision, for
> which, in normal settings, a = a + 1e-17.

I don't think it's expected in this sense. The question is why the
exact same sequence of arithmetic ops on lists yields zero error but
on arrays yields 3.6e-15 error. This doesn't seem to be about lists
not showing full precision of the values, because the differences are
even zero when extracted from the lists.

>> Because it seems sooo weird to me.
>
> It shouldn't :) The usual answer is that you should read this:
>
> http://docs.sun.com/app/docs/doc/800-7895

This doesn't help! This is a python question, methinks.

Best,
Rob
```