Re: Applying a list of 2D paramters to a mathematica function
- To: mathgroup at smc.vnet.net
- Subject: [mg68081] Re: [mg68041] Applying a list of 2D paramters to a mathematica function
- From: gardyloo <gardyloo at mail.wsu.edu>
- Date: Fri, 21 Jul 2006 17:36:38 -0400 (EDT)
- References: <200607210937.FAA06876@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, Curry,
Here are some ways to do what you want. You have to either re-define
your function (seems easiest to me), or change the way you're applying
it to the list (duh!).
In[13]:=
f[x_, y_] := x + y;
indices = {{a, b}, {c, d}, {e, f}}
Out[14]=
{{a, b}, {c, d}, {e, f}}
In[19]:=
(f[#1[[1]], #1[[2]]] & ) /@ indices
Out[19]=
{a + b, c + d, e + f}
In[20]:=
f2[(x_)?ListQ] := x[[1]] + x[[2]]
In[22]:=
f2 /@ indices
Out[22]=
{a + b, c + d, e + f}
In[29]:=
Apply[#1 + #2 & , indices, {1}]
Out[29]=
{a + b, c + d, e + f}
Curry Taylor wrote:
> I have (for simplicity) something like this:
>
> f[x_, y_] := x+y;
>
> I want to use this function for a variety of parameters in a list:
>
> indices = {{a,b}, {c,d}, {e,f}, ..}
>
> so that I get
>
> {a+b, c+d, e+f, ..}
>
> Doing the intuitive thing (for me)
>
> f /@ indices
>
> results in
>
> {f[{a, b}], f[{c, d}], f[{e, f}], ..}
>
> but what I want is
>
> {f[a, b], f[c, d], f[e, f], ..}
>
> and that's not what I'm getting. I have tried using Flatten, pure
> functions (Slot # and &), different Map functions, nesting at parameters
> (like {1} and {2}), and other things but I just can't seem to get what I'm
> after. Any help please?
>
> Thank you,
>
> Curry
>
>
>
--
==========================================================
Curtis Osterhoudt
gardyloo at mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================
--------------060609090103010209020304
name="gardyloo.vcf"
filename="gardyloo.vcf"
YmVnaW46dmNhcmQNCmZuOkN1cnRpcyAgT3N0ZXJob3VkdA0KbjpPc3RlcmhvdWR0O0N1cnRp
cyANCmVtYWlsO2ludGVybmV0OmdhcmR5bG9vQG1haWwucmVtb3ZlX3RoaXMud3N1LmFuZF90
aGlzLmVkdQ0KdGVsO3dvcms6NTA5LjMzNS40OTQ2DQpub3RlOlBHUCBLZXkgSUQ6IDB4MDg4
RTZEN0ENCngtbW96aWxsYS1odG1sOkZBTFNFDQp2ZXJzaW9uOjIuMQ0KZW5kOnZjYXJkDQoN
Cg==
--------------060609090103010209020304--
- References:
- Applying a list of 2D paramters to a mathematica function
- From: Curry Taylor <curry@192.168.0.101>
- Applying a list of 2D paramters to a mathematica function