You just don't have enough accuracy. float32 has only about 7 digits of precision, while float64 has about 16 digits of precision. Thus, whenever you convert to float32 , it is only guaranteed to be "correct" with an accuracy of 10 ^ 7. So, for example, you can try the following:
>>> np.array([20000001]).astype('float64') array([ 20000001.])
This is the expected answer. ( dtype=float64 automatically omitted because this is the default value.) In fact, you can go ahead and find
>>> np.array([2000000000000001]).astype('float64')[0] 2000000000000001.0
but
>>> np.array([20000000000000001]).astype('float64')[0] 20000000000000000.0
At some point, no matter how high your accuracy, you always get to the point where the least significant numbers are dropped by the float . See here for more information on float s.
On the other hand, python int objects have a lot more digits that they can track. In python 3 it is almost unlimited. So int has basically infinite precision. See here for more information on int s.
source share