What is the reason that these two divisions give different results? I am very confused, because with some numbers it gives the same results, and with some - not.
>>> import numpy as np
>>> a, b = np.array([844]), np.array([8186])
>>> a.dtype, b.dtype
(dtype('int32'), dtype('int32'))
>>> np.true_divide(a, b, dtype=np.float32)
array([ 0.10310286], dtype=float32)
>>> np.true_divide(a, b, dtype=np.float64)
array([-12.66666667])
>>> np.true_divide(a, b, dtype=np.float32).astype(np.float64)
array([ 0.10310286])
>>> a, b = np.array([1]), np.array([2])
>>> np.true_divide(a, b, dtype=np.float32)
array([ 0.5], dtype=float32)
>>> np.true_divide(a, b, dtype=np.float64)
array([ 0.5])
Tested on windows x64, python 3.5 and 3.6 x64, numpy 1.13.1.
source
share