MathGroup Archive 1998

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

Search the Archive

Re: list combinations



Daniel Sanders wrote:
> 
> Hi All,
> 
> I have a bit of bother here about creating a list.  The problem: Given a
> set of lists of the same dimension, example
> list={{1,2},{2,3},{5,6},{7,8}}, I want to join them in sets of two such
> that every combination is joined.  So, if list is of Dimensions={5,2},
> the new list will be of Dimensions={10,2,2}.  I think that states the
> basic problem.  I want to use standard issue Mathematica functions
> without calling up a package, or simulating the style of another
> program language like Pascal.
> 
> Thanks in advance for any help.
> 
> Dan


In[18]:= list = {{1,2},{2,3},{5,6},{7,8}};

In[19]:= Dimensions[list]
Out[19]= {4, 2}

In[20]:= combos = Flatten[Table[{list[[j]],list[[k]]},
    {j,Length[list]-1}, {k,j+1,Length[list]}], 1]
Out[20]= {{{1, 2}, {2, 3}}, {{1, 2}, {5, 6}}, {{1, 2}, {7, 8}},
>    {{2, 3}, {5, 6}}, {{2, 3}, {7, 8}}, {{5, 6}, {7, 8}}}

In[21]:= Dimensions[combos]
Out[21]= {6, 2, 2}

Daniel Lichtblau
Wolfram Research



  • Prev by Date: ListPlots, sizing
  • Next by Date: RE: Re: Active Plots
  • Prev by thread: list combinations
  • Next by thread: Re: list combinations