0

I have a 1D tensor a of float64 numbers and I want to extract unique values. After running torch.unique(a) or np.unique(a), I get an array which has a duplicate entries on the last two positions:

[-14.5 -13.5 -12.5 ... 23.5  24.5  24.5]

When I subtract the last two elements, I get

-3.552713678800501e-15

I suppose this happens because of floating point precision. Is there some way to efficiently find unique numbers (for example within some reasonable epsilon neighborhood)?

Thanks!

Vojtooo
  • 103
  • 2
  • 6
  • 1
    Does this answer your question? [Find unique elements of floating point array in numpy (with comparison using a delta value)](https://stackoverflow.com/questions/5426908/find-unique-elements-of-floating-point-array-in-numpy-with-comparison-using-a-d) – Michael Butscher Mar 09 '23 at 16:42
  • 1
    So, those functions*are working*, you just want to do something else. Anyway, the best I can come up with is sort then binary search for the closest and reject if within but it's not going to be super efficient. – juanpa.arrivillaga Mar 09 '23 at 16:43

0 Answers0