MathGroup Archive 2000

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

Search the Archive

Re: Mapping down two lists

  • To: mathgroup at
  • Subject: [mg25211] Re: [mg25179] Mapping down two lists
  • From: Matt.Johnson at
  • Date: Fri, 15 Sep 2000 02:21:47 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


lst1 = Table[Random[], {500000}];
lst2 = Table[{Random[], Random[]}, {500000}];
Plus @@ (Transpose[lst2][[1]] - lst1)^2) // Timing
{1.87 Second, 83259.7}
Apply[Plus, (#[[1]] & /@ lst2 - lst1)^2] // Timing
{2.91 Second, 83259.7}


"John Satherley" <js1 at> on 09/12/2000 07:24:23 PM


Subject: [mg25211]  [mg25179] Mapping down two lists

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

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

The best I have come up with is:
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
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
js1 at

  • Prev by Date: Re: Random spherical troubles
  • Next by Date: ParametricPlot3D is buggy
  • Previous by thread: Re: Mapping down two lists
  • Next by thread: Re: Mapping down two lists