MathGroup Archive 2010

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

Search the Archive

Re: List of multiple elements

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112105] Re: List of multiple elements
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Tue, 31 Aug 2010 04:14:50 -0400 (EDT)
  • References: <i5d019$bs8$1@smc.vnet.net> <i5g0hu$gos$1@smc.vnet.net>

On Aug 30, 3:18 am, Ray Koopman <koopman at sfu.ca> wrote:
>
> dupels2 is a faster version of DuplicateElements:
>
> dupels2[v_List] := Module[{f,dups={}},
> f[n_] := (f[n] := (dups = {dups,n})); f/@v; Flatten@dups]
>
> DupsOnlee is an unsorted version of DupsOnly:
>
> DupsOnlee[v_List] := Fold[DeleteCases[#1, #2, {1}, 1] &, v, Union@v]

If you can tolerate sorted results then sordups
is 10x faster than dupels2 and DupsOnlee.

sordups[v_List] := Flatten[Rest/@Split@Sort@v]

{m,n} = {50,1*^4}
Timing[w = Table[Random[Integer,{1,m}],{n}]; Do[Null,{1*^7}]];
First@AbsoluteTiming[t1 = dupels2[w];]
First@AbsoluteTiming[t2 = DupsOnlee[w];]
First@AbsoluteTiming[t3 = sordups[w];]
Sort@t1 === Sort@t2 === t3

{50,10000}
0.060016 Second
0.071353 Second
0.006265 Second
True


  • Prev by Date: Re: find selected function / F1
  • Next by Date: Re: Working with Log
  • Previous by thread: Re: List of multiple elements
  • Next by thread: Re: i get an empty figure when exporting it, if I keep