[Numpy-discussion] arrays comparison issue

Lev Givon lev@columbia....
Wed Nov 4 08:59:53 CST 2009


Received from Jean-Luc Menut on Wed, Nov 04, 2009 at 09:52:15AM EST:
> Hello all,
> 
> 
> 
> If if define 2 variables a and b by doing the following :
> 
> on [5]: a
> Out[5]: array([ 1.7])
> 
> In [6]: b=array([0.8])+array([0.9])
> 
> In [7]: b
> Out[7]: array([ 1.7])
> 
> 
> if I test the equality of a and b, instead to obatin True, I have :
> In [8]: a==b
> Out[8]: array([False], dtype=bool)
> 
> I know it not related only to numpy but also to python.
> How do you tackle this problem ?
> 
> (I also tried on IDL and it works well : I guess it truncate the number).
> 
> Thanks ,

Try using the numpy.allclose function (with a suitable tolerance) to
compare the arrays.

							L.G.


More information about the NumPy-Discussion mailing list