Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4611
| From | Armand Tamzarian <mike.honeychurch@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Replace |
| Date | 2011-08-27 12:22 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j3anhr$hg0$1@smc.vnet.net> (permalink) |
| References | <j35am1$og8$1@smc.vnet.net> <j37p96$4lk$1@smc.vnet.net> |
On Aug 26, 7:33 pm, Armand Tamzarian <mike.honeychu...@gmail.com>
wrote:
> On Aug 25, 9:12 pm, Sam Korn <s...@kornfamily.com> wrote:
>
> > Hi, another stupid question. I have a list, and each element in the list is
> > a sublist with a pair of integers. How do I replace each element along the
> > lines of "{5,6}" with "(5|6)"?
>
> > I know it's a stupid question, and there's probably something really obvious
> > I'm missing, but I'm really new to Mathematica.
>
> > Thanks!
> > -Sam
>
> Here are a couple of ways:
>
> tmp = RandomInteger[{1, 20}, {20, 2}]
>
> First using Replace
>
> tmp /. {x_, y_} :> x/y
>
> For many this is a more intuitive way of doing it but will be
> (relatively) slow for very large lists. This is a faster way of doing
> it:
>
> tmp[[All, 1]]/tmp[[All, 2]]
>
> Mike
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
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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