Re: "Sloppy Union"? (Union of a list with *nearly* equal elements)
- To: mathgroup at smc.vnet.net
- Subject: [mg41912] Re: "Sloppy Union"? (Union of a list with *nearly* equal elements)
- From: wself at msubillings.edu (Will Self)
- Date: Mon, 9 Jun 2003 05:20:56 -0400 (EDT)
- References: <bbv4ni$23f$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
AES/newspost <siegman at stanford.edu> wrote in message news:<bbv4ni$23f$1 at smc.vnet.net>... > I'm trying to make a "Sloppy Union" that will eliminate elements of a > list that are *almost* but not precisely duplicates of each other; and > Union[ ] has the "SameTest->test" option which looks like what I need. > > I don't understand, however, why the following approach seems to work > > Remove["Global`*"] > > sloppyData = Table[Random[Integer, {1000,1005}] > + Random[Real, {-0.01,0.01}], {20}] > > Union[sloppyData, SameTest -> (Abs[#1-#2]<10.^-1&)] > > but the following doesn't > > Remove["Global`*"] > > sloppyData = Table[Random[Integer, {1000,1005}] > + Random[Real, {-0.01,0.01}], {20}] > > sharperData = SetPrecision[sloppyData, 4] > > Union[sharperData, SameTest -> (Abs[#1-#2]<10.^-1&)] > > --even though shaperData seems to have reduced precision. SetPrecision doesn't actually change the data. FullForm[SetPrecision[1000.2, 4]] Union, along with SameTest, is working with the original data. You can use Round to actually change the data.