[Numpy-discussion] float64 / int comparison different from float / int comparison

Stéfan van der Walt stefan@sun.ac...
Mon Oct 31 20:38:24 CDT 2011


On Mon, Oct 31, 2011 at 6:25 PM, Matthew Brett <matthew.brett@gmail.com> wrote:
> Oh, dear, I'm suffering now:
>
> In [11]: res = np.array((2**31,), dtype=np.float32)
>
> In [12]: res > 2**31-1
> Out[12]: array([False], dtype=bool)
>
> OK - that's what I was expecting from the above, but now:
>
> In [13]: res[0] > 2**31-1
> Out[13]: True
>
> In [14]: res[0].dtype
> Out[14]: dtype('float32')

I'm seeing:

In [7]: res = np.array((2**31,), dtype=np.float32)

In [9]: res > (2**31-1)
Out[9]: array([ True], dtype=bool)

In [10]: res[0]
Out[10]: 2.1474836e+09

In [11]: res[0] > (2**31-1)
Out[11]: True

Your result seems very strange, because the numpy scalars should
perform exactly the same inside and outside an array.

Stéfan


More information about the NumPy-Discussion mailing list