MathGroup Archive 2010

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

Search the Archive

Re: multiple variables in pure function used in map.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107650] Re: multiple variables in pure function used in map.
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 21 Feb 2010 04:25:50 -0500 (EST)

On 2/20/10 at 6:38 AM, pipehappy at gmail.com (pipehappy) wrote:

>Is there a way to use multiple variables in pure function with map.

>What I want to do is like this:

>ab = {{1, 2}, {2, 3}, {3, 4}}; (#[[1]] + #[[2]]) & /@ ab {3, 5, 7}

>Instead of refer to elements in list I want to use multiple
>variables in pure function.

>something like this: ab = {{1, 2}, {2, 3}, {3, 4}}; (#1 + #2) & /@
>ab To do the same thing as the above example.

Use Apply. For example,

In[5]:= Plus @@ # & /@ ab

Out[5]= {3,5,7}

Or perhaps better, dispense with Map and do

In[6]:= Plus @@@ ab

Out[6]= {3,5,7}

Or

In[7]:= Apply[Plus, ab, {1}]

Out[7]= {3,5,7}




  • Prev by Date: Re: multiple variables in pure function used in map.
  • Next by Date: Re: multiple variables in pure function used in map.
  • Previous by thread: Re: multiple variables in pure function used in map.
  • Next by thread: Re: multiple variables in pure function used in map.