Re: Mapping down two lists
- To: mathgroup at smc.vnet.net
- Subject: [mg25212] Re: [mg25179] Mapping down two lists
- From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
- Date: Fri, 15 Sep 2000 02:21:47 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Maybe the following is a little nicer: Plus @@ First[Transpose[l1 - l2]]^2 Andrzej -- Andrzej Kozlowski Toyama International University, JAPAN For Mathematica related links and resources try: <http://www.sstreams.com/Mathematica/> on 9/13/00 10:24 AM, John Satherley at js1 at liverpool.ac.uk wrote: > Hi MathGroup > I'm trying to sharpen up my functional programming skills and have come > across a problem which is probably very trivial but I can't find a > satisfactory solution. > > I have two lists of equal length, one 2 dimensional and the other 1 > dimensional: > lst1={{1,2},{2,3},{1,3},......} > lst2={1,2,2,3,4,5.....} > > What I want to do is find the difference between lst1[[i,1]] and lst2[[i]] > square it and then sum up all the terms over the length of the list. > > It is easy to do this in terms of Tables but I'm trying to find a fast > solution for long lists that uses map and other functional programming > tools. > > The best I have come up with is: > Apply[Plus,([#[[1]]&/@lst1-lst2)^2] > but I'm wondering if it is possible to map directly onto the two lists > without first having to extract the elements of the first list? Map seems to > only work down a single list. > > I would be most grateful of any hints as to how this might be performed in > an efficient manner. > > Thanks for help > Dr. John Satherley > Dept of Chem > University of Liverpool > Liverpool L69 7ZD > UK > js1 at liv.ac.uk > > > >