[Numpy-discussion] float64 / int comparison different from float / int comparison
Matthew Brett
matthew.brett at gmail.com
Mon Oct 31 21:25:35 EDT 2011
Hi,
2011/10/31 Stéfan van der Walt <stefan at sun.ac.za>:
> On Mon, Oct 31, 2011 at 11:23 AM, Matthew Brett <matthew.brett at gmail.com> wrote:
>> In [8]: np.float(2**63) == 2**63
>> Out[8]: True
>>
>> In [9]: np.float(2**63) > 2**63-1
>> Out[9]: True
>>
>> In [10]: np.float64(2**63) == 2**63
>> Out[10]: True
>>
>> In [11]: np.float64(2**63) > 2**63-1
>> Out[11]: False
>>
>> In [16]: np.float64(2**63-1) == np.float(2**63-1)
>> Out[16]: True
>
> Interesting. Turns out that np.float(x) returns a Python float
> object. If you change the experiment to only use numpy array scalars,
> things are more consistent:
>
> In [36]: np.array(2**63, dtype=np.float) > 2**63 - 1
> Out[36]: False
>
> In [37]: np.array(2**63, dtype=np.float32) > 2**63 - 1
> Out[37]: False
>
> In [38]: np.array(2**63, dtype=np.float64) > 2**63 - 1
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')
Sorry, maybe I'm not thinking straight, but I'm confused...
See you,
Matthew
More information about the NumPy-Discussion
mailing list