MathGroup Archive 2002

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

Search the Archive

RE: Again, How to speed up this calculation? and more

  • To: mathgroup at
  • Subject: [mg37272] RE: [mg37246] Again, How to speed up this calculation? and more
  • From: "DrBob" <drbob at>
  • Date: Mon, 21 Oct 2002 02:29:45 -0400 (EDT)
  • Reply-to: <drbob at>
  • Sender: owner-wri-mathgroup at

Why make a list of them at all?  That is, you know what the pairs are
without listing them, and you can form any pair you want without listing
them.  So -- why spend all that memory, even if you have it?  (And you
don't.)  I just see no reason for it.


-----Original Message-----
From: Cheng Liu [mailto:cliu at] 
To: mathgroup at
Subject: [mg37272] [mg37246] Again, How to speed up this calculation? and more

Dear group,

         Thank you all for the responses.  I might not make my question 
very clear.  Suppose that I have a list of points {p1,p2, ..., pn}, I
to find all possible pairs of them.  The pairs may include {pi,pi}, but 
{pi,pj} and {pj,pi} are considered the same and only one is counted.

         That said.  After some try and error, I came to the following


The speed of the above calculation is reasonably fast.  But I run into
memory problem.  For example, for h=64 and w=64, the length of the list 
pairs will be w*h (w*h+1)/2 = 8,390,656.  In my case, The numbers for h
w will be a lot larger than 64.  How can I get around this memory
or that's the dead end for my calculation (I do have 1 GB physical mem
my machine)?  Thanks a lot.


At 12:26 PM 10/16/2002, you wrote:
>Dear group,
>          I have the following question regarding a lengthy calculation
>using Mathematica:
>For given w points in x direction and h points in y direction, I can
>construct all the points using
>          h=10; w=8;
>          points=Flatten[Transpose[Outer[List,Range[w],Range[h]]],1]
>Next, I need to find all the possible pairs of point including points
>themselves, i.e., pair AA.  I can use
>          pairs=Outer[List,points,points,1]
>Then, I have to clear those pairs that repeat themselves, i.e., pair AB
>pair BA.  Also, when w and h are of the order of 1000s, the computation
>takes a very long time.  Is there a better way of doing the second part
>the computation?  Thanks in advance.
>Cheng Liu, Ph.D.
>MST-8, Structure/Property Relations
>Materials Science and Technology Division
>Los Alamos National Laboratory
>Los Alamos, New Mexico 87545
>Phone: 505-665-6892 (office), 505-667-9950 (lab)
>Fax:   505-667-8021
>email: cliu at

Cheng Liu, Ph.D.
MST-8, Structure/Property Relations
Materials Science and Technology Division
Los Alamos National Laboratory
Los Alamos, New Mexico 87545

Phone: 505-665-6892 (office), 505-667-9950 (lab)
Fax:   505-667-8021
email: cliu at

  • Prev by Date: problem with Collect[] for long polynomial
  • Next by Date: Raising Contour Plot Graphics to 3D - II
  • Previous by thread: Re: Again, How to speed up this calculation? and more
  • Next by thread: Formatting and Printing