Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: programming problem about elements taken

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72484] Re: programming problem about elements taken
  • From: Peter Pein <petsie at dordos.net>
  • Date: Mon, 1 Jan 2007 03:51:01 -0500 (EST)
  • References: <en5evt$l12$1@smc.vnet.net> <en82bm$6nb$1@smc.vnet.net>

Dear group,

please ignore this nonsense.

Thank you.

Peter Pein schrieb:

> Hi Barrow,
> 
> the first method coming to my mind has been the use of ReplaceRepeated, but
> for long lists this lasts far too long:
> 
> 
> A=Table[Random[],{2000}];
> epsilon=1.*^-4;
> 
> Timing[Length[
>     r1=A//.{x___,c_,y___}/;Min[Abs[c-{x,y}]]<epsilon:>{x,y}
>     ]]
> 
> --> {22.125 Second,1650}
> 
> It is sufficient to compare element k with elements k+1,...,n:
> 
> selectDistinguishable[a_List,eps_]:=
>   Pick[a,Min[Abs[a[[#]]-Drop[a,#]]]>eps&/@Range[Length[a]]]
> 
> Timing[Length[
>     r2=selectDistinguishable[A,epsilon]
>     ]]
> 
> --> {0.11 Second,1650}
> 
> _Much_ better :-)
> 
> r1===r2
> --> True
> 
> hth,
> Peter
> 


  • Next by Date: Re: programming problem about elements taken
  • Next by thread: Re: programming problem about elements taken