When I cast the numbers in the matrix as np.float32
the values are slightly modified:
In [1]: matrix_32 = np.asarray([
...: [0.7, 3],
...: [1.7, 2],
...: [0.7, 9]
...: ], dtype=np.float32)
In [2]: matrix_32
Out[2]:
array([[ 0.69999999, 3. ],
[ 1.70000005, 2. ],
[ 0.69999999, 9. ]], dtype=float32)
However, when I cast the numbers as np.float64
the values are shown as expected:
In [3]: matrix_64 = np.asarray([
...: [0.7, 3],
...: [1.7, 2],
...: [0.7, 9]
...: ], dtype=np.float64)
In [4]: matrix_64
Out[4]:
array([[ 0.7, 3. ],
[ 1.7, 2. ],
[ 0.7, 9. ]])
Can somebody explain why this happens?