Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4628

Re: Replace

From Peter Pein <petsie@dordos.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Replace
Date 2011-08-28 08:09 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j3ct3f$5m7$1@smc.vnet.net> (permalink)
References <j35am1$og8$1@smc.vnet.net> <j37p96$4lk$1@smc.vnet.net> <j3anhr$hg0$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Replace Sam Korn <sam@kornfamily.com> - 2011-08-25 11:12 +0000
  Re: Replace Ray Koopman <koopman@sfu.ca> - 2011-08-26 09:27 +0000
  Re: Replace "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-26 09:30 +0000
  Re: Replace Peter Breitfeld <phbrf@t-online.de> - 2011-08-26 09:31 +0000
  Re: Replace Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-08-26 09:33 +0000
    Re: Replace Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-08-27 12:22 +0000
      Re: Replace Peter Pein <petsie@dordos.net> - 2011-08-28 08:09 +0000
    Re: Replace Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-08-29 07:49 +0000
  Re: Replace Peter Pein <petsie@dordos.net> - 2011-08-26 09:35 +0000
  Re: Replace Murray Eisenberg <murray@math.umass.edu> - 2011-08-27 12:25 +0000
    Re: Replace Ray Koopman <koopman@sfu.ca> - 2011-08-28 08:06 +0000
  Re: Replace Murray Eisenberg <murray@math.umass.edu> - 2011-08-28 08:13 +0000

csiph-web