MathGroup Archive 2007

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

Search the Archive

Re: programming problem about elements taken


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