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: [mg107636] Re: multiple variables in pure function used in map.
  • From: "Norbert P." <bertapozar at gmail.com>
  • Date: Sun, 21 Feb 2010 04:23:17 -0500 (EST)
  • References: <hlohjt$d95$1@smc.vnet.net>

Hey,

use Apply with level specification:

Apply[(#1 + #2) &, ab, {1}]
{3, 5, 7}

Or simply
(#1 + #2) & @@@ ab

In this particular case even better
Plus @@@ ab

Best,
Norbert


On Feb 20, 3:38 am, pipehappy <pipeha... at gmail.com> wrote:
> Hi, All
>
> 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.
>
> Best
>
> -- pipehappy



  • 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.