I'm trying to find a set of unique floats in numpy array and realized that the content of the array is different when I use the set() after rounding on the numpy array. This is what happens when I enter the script in command prompt (or run .py)
import numpy as np
>>> a = np.array([12.32, 2.32, 1.0])
>>> a
array([12.32, 2.32, 1. ])
>>> b = np.round(a, 1)
>>> b
array([12.3, 2.3, 1.])
>>> c = set(b)
>>> c
set([2.2999999999999998, 12.300000000000001, 1.0])
what in the world is going on? I'm using Python 2.7.10 and numpy 1.9.2
NOTE: The question Python float - str - float weirdness was proposed as a duplicate. However, I don't think this is a str(), repr() issue since I've checked all the variable a, b, and c using both str and repr method and they both give same values.
I've also tried it with np.unique and the issue does not come up, so it may be some issue with set(). Or it could also be some float conversion error to and from numpy array as suggested.