[SciPy-user] Numpy/Scipy float precision vs Python list float issue
Ruben Salvador
rsalvador.wk@gmail....
Mon Apr 20 08:58:01 CDT 2009
Hi everybody!
First of all I should say I am a newbie with Python/Scipy. Have been
searching a little bit (google and lists) and haven't found a helpful
answer...so I'm posting.
(sorry for double posting, since I also just posted this in
numpy-discussion...just in case some of you are in both lists....but I
didn't figure out which only list should I post this to)
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? Because it seems sooo weird to me. If expected,
anyway to override it?
I include some test code for you to reproduce. It's part of a transform over
a 8x8 2D signal (for simplicity). It's not complete (again for simplicity),
but enough to reproduce. It does part of a forward and inverse transform
both with lists and arrays, printing the differences (there is commented
code showing some plots with the results as I used when transforming real
images, but for the purpose, is enough with the return results I think).
Code is simple (maybe long but it's always the same). Instead of using the
faster array slicing as commented above, I am using here array looping, so
that the math code is exactly the same as in the case list.
This happens in the next three system/platforms.
* System 1 (laptop):
---------------------------
64 bit processor running Kubuntu 8.04 32 bits
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52
Numpy version: 1:1.0.4-6ubuntu3
Scipy version: 0.6.0-8ubuntu1
* System 2 (PC):
--------------------------
Windows Xp on 64 bit processor
Enthought Python distribution (EPD Py25 v4.1.30101). This is a Python 2.5.2
with Numpy 1.1.1 and Scipy 0.6.0
* System 3 (same PC as 2):
--------------------------------------
Debian Lenny 64 bit on 64 bit processor
Not sure about versions here, but doesn't mind because behavior is prety
much the same in the 3 systems
Thanks everybody in advance for the help!
Ruben Salvador
PhD Student
Industrial Electronics Center
Universidad Politecnica de Madrid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20090420/3bb95849/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: floattest.py
Type: text/x-python
Size: 7160 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20090420/3bb95849/attachment.py
More information about the SciPy-user
mailing list