Re: Dot or Inner ... but not quite
- To: mathgroup at smc.vnet.net
- Subject: [mg79656] Re: [mg79622] Dot or Inner ... but not quite
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 1 Aug 2007 05:02:17 -0400 (EDT)
- References: <200707311013.GAA21053@smc.vnet.net>
On 31 Jul 2007, at 12:13, Diamond, Mark 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 > > > Note that 1*{1, 7} + 4*{1, 9} + 3*{5, 2} {20, 49} while (#1[[1]]*#1[[2]] & ) /@ Transpose[{l1, l2}] {{1, 7}, {4, 36}, {15, 6}} If the first answer is really what you want I would use: l1.Hold /@ l2 // ReleaseHold {20, 49} Andrzej Kozlowski