MathGroup Archive 2011

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

Search the Archive

Re: Replace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121100] Re: Replace
  • From: Peter Pein <petsie at dordos.net>
  • Date: Sun, 28 Aug 2011 04:05:07 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j35am1$og8$1@smc.vnet.net> <j37p96$4lk$1@smc.vnet.net> <j3anhr$hg0$1@smc.vnet.net>

Am 27.08.2011 14:22, schrieb Armand Tamzarian:
...
> Doh! you wanted "|" not "/"
> 
> It still looks like using Part will give the fastest solution (on my
> system at least, 8.0.1 OS X 10.6.8)
> 
> tmp = RandomInteger[{1, 20}, {20000, 2}];
> 
> Timing[tmp /. {x_, y_} :> x | y;]
> 
> Timing[Alternatives @@@ tmp;]
> 
> Timing[Thread[tmp[[All, 1]] | tmp[[All, 2]]];]
> 
> Mike
> 

Transpose seems to be even a bit faster than Part:

In[1]:= tmp = RandomInteger[{1, 20}, {2000000, 2}];
{t, r} = Transpose[{
           Timing[tmp /. {x_, y_} :> x | y],
           Timing[Apply[Alternatives, tmp, {1}]],
           Timing[Thread[tmp[[All,1]] | tmp[[All,2]]]],
           Timing[Thread[Alternatives @@ Transpose[tmp]]]}
        ];
t
SameQ @@ r

Out[3]= {1.56,0.764,0.624,0.531}
Out[4]= True




  • Prev by Date: Re: With Nearest
  • Next by Date: Re: Function of N variable
  • Previous by thread: Re: Replace
  • Next by thread: Re: Replace