MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Dropping Similar Numbers from List

  • To: mathgroup at
  • Subject: [mg60586] Re: [mg60564] Dropping Similar Numbers from List
  • From: "David Park" <djmp at>
  • Date: Wed, 21 Sep 2005 03:20:19 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


{SameTest -> Automatic}

I'm going to use 10^-12 as a cutoff just so we can better see an example.

testlist = {1, 2, 1, 2, 1, 2} + Table[10*^-13 Random[], {6}]
% // InputForm

{1., 2., 1., 2., 1., 2.}
{1.0000000000005198, 2.000000000000947, 
 1.0000000000004527, 2.0000000000004654, 
 1.0000000000003908, 2.0000000000003486}

Union[testlist, SameTest -> (Abs[#1 - #2] < 10*^-12 &)]
{1., 2.}

David Park
djmp at 

From: andre [mailto:erasmus.the.giant at]
To: mathgroup at

My data set has some numbers which differ by a small amount, say one
part in 10^-15, that I don't want to appear more than once.  If they
were identical, I would just use Union[data] and be finished.  Is there
a way to set a tollerance for the Union function?

I tried to use SetPrecision to get rid of the unwanted extra digits,
but Union[SetPrecision[data,n]] gives the same result as Union[data].
What exactly does SetPrecision do?  It seems that it's not just
dropping the digits beyond the limit I set.


  • Prev by Date: Re: Re: Differences between recursions and limit
  • Next by Date: Re: init.m
  • Previous by thread: Re: Dropping Similar Numbers from List
  • Next by thread: Re: Dropping Similar Numbers from List