0

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?

2
  • 1
    It most likely has to do with numpy print options vs. float print option. Commented Feb 12, 2021 at 21:28
  • 1
    Same as print(list(x)). Commented Feb 12, 2021 at 22:07

1 Answer 1

2

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 ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.