MathGroup Archive 2000

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

Search the Archive

Re: Mapping down two lists

  • To: mathgroup at
  • Subject: [mg25220] Re: [mg25179] Mapping down two lists
  • From: Tomas Garza <tgarza01 at>
  • Date: Fri, 15 Sep 2000 02:21:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On first sight, I think that perhaps the simplest approach would be:

lst1 == {{1, 2}, {2, 3}, {1, 3}, {3, 7}, {2, 9}};
lst2 == {1, 2, 2, 3, 4};

Plus @@ ((Transpose[lst1][[1]] - lst2)^2)

This doesn't require any notion of functional programming other than Apply.
 Of course you have to extract the first element of each element of the first
 list, but this can't be helped anyway. However, Transpose is an extremely
 fast operation.

Tomas Garza
Mexico City

John Satherley wrote:

> 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.

  • Prev by Date: Re: Add the Logarithms (error in integral)
  • Next by Date: Re: writing mathematica script files for the math kernel under linux
  • Previous by thread: Re: Mapping Down Two Lists
  • Next by thread: Re: Mapping down two lists