Re: pure functions
- To: mathgroup at smc.vnet.net
- Subject: [mg23299] Re: [mg23237] pure functions
- From: BobHanlon at aol.com
- Date: Sun, 30 Apr 2000 21:13:49 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
exli = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
(#[[1]] + #[[2]]) & /@ exli
{3, 7, 11, 15}
((Plus @@ #) & /@ exli)
{3, 7, 11, 15}
m = Array[x, {3, 3}];
(#[[1]] + #[[2]] + #[[3]]) & /@ m
{x[1, 1] + x[1, 2] + x[1, 3], x[2, 1] + x[2, 2] + x[2, 3],
x[3, 1] + x[3, 2] + x[3, 3]}
((Plus @@ #) & /@ m)
{x[1, 1] + x[1, 2] + x[1, 3], x[2, 1] + x[2, 2] + x[2, 3],
x[3, 1] + x[3, 2] + x[3, 3]}
In a message dated 4/29/2000 10:35:57 PM, helgea at inoc.chalmers.se writes:
>Of all the nice functions such as Map, Mapall, Thread, Apply .... I have
>not been able to write a simple code to generate the following
>procedure.
>
>I have a two dimensional list like
>
>li={{11,12,13,..},{21,22,23,...},{31,32,33,..},...}
>
>Since i like to use the pure function command I would like to map my
>pure function with arguments #1,#2,#3,.... on all the sublists in li.
>
>Let me exemplify with a simple pure function that add to numbers.
>(#1+#2)&
>
>if exli={{1,2},{3,4},{5,6},{7,8}}
>
>then I want to get the result
>{3,7,11,15}
>
>One solution, but not allways suitable for me, is the following
>
>(#1+#2)&[Sequence @@ Transpose[exli]].
>
>I want to get rid of the Transpose command and if possible also making
>use of the /@ notation for Map. Since I have seen so many elegant
>examples in the mailing lists I hope I can get something out of this.
>
Bob
BobHanlon at aol.com