MathGroup Archive 2011

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

Search the Archive

Re: Replace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121083] Re: Replace
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Fri, 26 Aug 2011 05:25:32 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j35am1$og8$1@smc.vnet.net>

On Aug 25, 9:12 pm, Sam Korn <s... at 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




  • Prev by Date: Re: CDF files now on Gyre&Gimble (math blog)
  • Next by Date: Re: Replace
  • Previous by thread: Re: Replace
  • Next by thread: Re: Replace