[Numpy-discussion] efficient way to manage a set of floats?

Robert Kern robert.kern at gmail.com
Wed May 12 21:27:16 EDT 2010


On Wed, May 12, 2010 at 20:09, Dr. Phillip M. Feldman
<pfeldman at verizon.net> wrote:
>
> Warren Weckesser-3 wrote:
>>
>> A couple questions:
>>
>> How many floats will you be storing?
>>
>> When you test for membership, will you want to allow for a numerical
>> tolerance, so that if the value 1 - 0.7 is added to the set, a test for
>> the value 0.3 returns True?  (0.3 is actually 0.29999999999999999, while
>> 1-0.7 is 0.30000000000000004)
>>
>> Warren
>>
>
> Anne- Thanks for that absolutely beautiful explanation!!
>
> Warren- I had not initially thought about numerical tolerance, but this
> could potentially be an issue, in which case the management of the data
> would have to be completely different.  Thanks for pointing this out!  I
> might have as many as 50,000 values.

You may want to explain your higher-level problem. Maintaining sets of
floating point numbers is almost never the right approach. With sets,
comparison must necessarily be by exact equality because fuzzy
equality is not transitive.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list