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

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Apr 20 13:54:35 EDT 2009


On Mon, Apr 20, 2009 at 1:47 PM, Matthieu Brucher <
matthieu.brucher at gmail.com> wrote:

> > I understand the numerical mathematics behind this very well but my
> > point is that his two algorithms appear to be identical (same
> > operations, same order), he simply uses lists in one and arrays in the
> > other. It's not like he used vectorization or other array-related
> > operations - he uses for loops in both cases. Of course I agree that
> > 1e-15 error should be acceptable, but that's not the point. I think
> > there is legitimate curiosity in wondering why there is any difference
> > between using the two data types in exactly the same algorithm.
>
> Hi,
> There are cases where the same algorithm implementation outputs
> different results in optimized mode, depending on data alignment. As
> David said, this is something that is known or at least better known.
>
>
in this example, there is no difference between numpy and python list if you
deepcopy
instead of mutating your original lists, see:

diff_npl = [[0.0]*width for i in range(height)]
for row in range(height):
    for col in range(width):
        diff_npl[row][col] = s[row][col] - sl[row][col]
print "\n* Difference numpy list:"
print diff_npl
print "maximum difference =>", max(diff_npl)
print "minimum diff =>", min(diff_npl)

* Difference numpy list:
[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]
maximum difference => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
minimum diff => [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090420/7a775c92/attachment.html>


More information about the NumPy-Discussion mailing list