[Numpy-discussion] Floating Point Difference between numpy and numarray

Hanni Ali hanni.ali@gmail....
Wed Sep 3 05:22:56 CDT 2008


I'm afraid the matrix is not available anywhere and I would not be able to
make it available.

However I can demonstrate by simply generating a random number and filling a
10x10 matrix with it.

I generated a random number in numpy and used that to do the same exercise
in numarray.

In numpy:

>>> matrix = numpy.zeros((10,10),'f')
>>> matrix
array([[ 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.]], dtype=float32)
>>> number = numpy.random.random_sample()
>>> number
0.41582016134572475
>>> matrix.setfield(number,'f',0)
>>> matrix
array([[ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567],
       [ 0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567,  0.415820151567,  0.415820151567,
         0.415820151567,  0.415820151567]], dtype=float32)
>>> matrix.mean()
0.41582069396972654

In numarray:
>>> matrix = numarray.zeros((10,10),'f')
>>> matrix
array([[ 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.]], type=Float32)
>>> number = 0.41582015156745911
>>> for i, item in enumerate(matrix):
...     matrix[i] = number
...
>>> matrix
array([[ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015],
       [ 0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015,  0.41582015,  0.41582015,
         0.41582015,  0.41582015]], type=Float32)
>>> matrix.mean()
0.41582015156745911







2008/9/3 David Cournapeau <david@ar.media.kyoto-u.ac.jp>

> Hanni Ali wrote:
> > Hi Matthieu,
> >
> > I thought as much, regarding the computations, but was just presenting
> > the information.
>
> Is your matrix available somewhere so that we can reproduce the problem
> ? Off-hand, I can't see any explanation, but I am not familiar with
> numarray, so maybe I am missing something obvious,
>
> cheers,
>
> David
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080903/803b2130/attachment.html 


More information about the Numpy-discussion mailing list