Re: Dot or Inner ... but not quite
- To: mathgroup at smc.vnet.net
- Subject: [mg79653] Re: [mg79622] Dot or Inner ... but not quite
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Wed, 1 Aug 2007 05:00:40 -0400 (EDT)
- Reply-to: hanlonr at cox.net
l1 = {a1, a2, a3}; l2 = {{b1, b2}, {c1, c2}, {d1, d2}}; Total[(#[[1]]*#[[2]]) & /@ Transpose[{l1, l2}]] {a1 b1+a2 c1+a3 d1,a1 b2+a2 c2+a3 d2} Total[l1*l2] {a1 b1+a2 c1+a3 d1,a1 b2+a2 c2+a3 d2} % == %% True Bob Hanlon ---- "Diamond wrote: > I have two equi-length lists, the first of number, the second of > (equi-length) lists of numbers , such as > > l1={1,4,3}; > l2={{1,7},{1,9},{5,2}}; > > I want to produce 1*{1,7}+4*{1,9}+3*{5,2} > > It looks so close to Inner that I thought I could use it in some form, but I > have ended up using > > (#[[1]]*#[[2]])& /@ Transpose[{l1,l2}] > > Is there a better way using one of the builtin functions with which I am > unfamiliar? > > Cheers, > > Mark Diamond > > >