Why does this fail? I create an array, create a new variable with that array minus a value from within the array, and then compare the array to a value that appears to be in the array. So why does the equality test fail?
import numpy as np
import platform
print platform.python_version()
print np.__version__
x = np.arange( -1,1,0.1 )
new_x = x - x[5]
print new_x
print new_x == -0.2
outputs:
2.7.9
1.9.2
[-0.5 -0.4 -0.3 -0.2 -0.1 0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. 1.1 1.2 1.3 1.4]
[False False False False False False False False False False False False False False False False False False False False]
EDIT: Using np.round() causes the comparison to behave as expected; the question now is, why am I being presented with rounded numbers when I print the array? In my experience python will usually print scientific notation or just a bunch of decimal places when the numbers are not exact.
Shockingly, I have been programming in python scientifically for 6 years and never seen this! It feels like a noob question but I really don't understand why what's printed is rounded.