Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Variant of inner Product ...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56741] Re: Variant of inner Product ...
  • From: Peter Pein <petsie at arcor.de>
  • Date: Thu, 5 May 2005 06:01:23 -0400 (EDT)
  • References: <d59jtg$69m$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Detlef M=FCller wrote:
> Hello,
>
> I have the following to do:
>
> Given
>
> In[1]:= A={1,2,3}; B={{a,b},{c,d},{r,s}};
>
> And a Function f, I like to have
>
> Out[2] = {f[1,a],f[1,b]}+{f[2,c],f[2,d]}+{f[3,r],f[3,s]}
>
> The trial
>
> In[8]:=A={1,2,3}; B={{a,b},{c,d,e},{r,s}};
> In[9]:= Inner[f,A,B]
> Out[9]= f[1,{a,b}]+f[2,{c,d,e}]+f[3,{r,s}]
>
> looks promising,
> but if the Lists in B have the same length, "Inner"
> makes something different:
>
> In[15]:=
> A={1,2,3}; B={{a,b},{c,d},{r,s}}; Inner[f,A,B]
>
> Out[16]= {f[1,a]+f[2,c]+f[3,r],f[1,b]+f[2,d]+f[3,s]}
>
> So for now I have an ugly Table-Construction doing the job,
> but I can't imagine there is no elegant and clear solution
> for this ... any suggestions?
>
> Greetings,
>    Detlef
>

A = {1, 2, 3}; B = {{a, b}, {c, d}, {r, s}};
goal = {f[1, a], f[1, b]} + {f[2, c], f[2, d]} + {f[3, r], f[3, s]};
goal == Plus @@ MapThread[Thread[f[##1]] & , {A, B}]

True

--
Peter Pein
Berlin


  • Prev by Date: InitializationCell -> Toggle shortcut key
  • Next by Date: Re: named pattern variable scoped as global, should be local
  • Previous by thread: Re: Variant of inner Product ...
  • Next by thread: Re: Variant of inner Product ...