Re: "vector" Map[] / functional outer product?

• To: mathgroup at smc.vnet.net
• Subject: [mg83792] Re: "vector" Map[] / functional outer product?
• From: Szabolcs Horvát <szhorvat at gmail.com>
• Date: Fri, 30 Nov 2007 05:29:43 -0500 (EST)
• References: <fim8tq\$rmd\$1@smc.vnet.net>

```Mitch Murphy wrote:
> greetings,
>
> is there a simpler way to express
>
> 	{f@#,g@#}& /@ {a,b,c}
>
> 	-> {{f[a],g[a]},{f[b],g[b]},{f[c],g[c]}}
>
> ie. is there some mathematica function ??? such that
>
> 	{f,g} ??? {a,b,c}
>
> 	-> {{f[a],g[a]},{f[b],g[b]},{f[c],g[c]}}

There is no single function, but there are many ways to do it.

In[6]:= Through /@ Thread[{f, g}[{a, b, c}]]
Out[6]= {{f[a], g[a]}, {f[b], g[b]}, {f[c], g[c]}}

>
> you might be asking what's so difficult about the "@#,@#,... & /@"
> syntax, but what about when you don't have two functions f,g but 8-10
> functions... the syntax gets ugly fast and hard to read.
>
> note that
>
> 	Outer[{f, g}, {a, b, c}]
>
> 	-> {{f, g}[a], {f, g}[b], {f, g}[c]}

In[2]:= Outer[{f, g}, {a, b, c}]
Out[2]= {{f, g}[a], {f, g}[b], {f, g}[c]}

In[3]:= Through /@ %
Out[3]= {{f[a], g[a]}, {f[b], g[b]}, {f[c], g[c]}}

>
> doesn't work, neither does
>
> 	Outer[Apply, {f, g}, {a, b, c}]
>
> 	->{{a, b, c},{a, b, c}}
>

In[4]:= Outer[#2[#1] &, {a, b, c}, {f, g}]
Out[4]= {{f[a], g[a]}, {f[b], g[b]}, {f[c], g[c]}}

Apply[] and #1[#2] are not the same thing.

--
Szabolcs

```

• Prev by Date: Re: "vector" Map[] / functional outer product?
• Next by Date: Re: Reading excel data
• Previous by thread: Re: "vector" Map[] / functional outer product?
• Next by thread: Re: "vector" Map[] / functional outer product?