I am working with the numpy array x = np.arange (2.5,7.0,0.01). If I give the commands print(x) and print(*x) I obtain different results. I know that *x unpack the numpy array, but I would expect the same values. For example, the last value printed by print(x) is 6.99, while the analogous one is 6.989999999999904. Why this discrepancy?
1 Answer
if you print a specific value, you get the same result. But while printing the whole array the values are truncated by the print() function
x = np.arange (2.5, 7.0, 0.01)
print(x[3])
the value is: 2.5299999999999994
when compared to
print(*x)
values : 2.5 2.51 2.5199999999999996 2.5299999999999994 ...
print(list(x)).