MathGroup Archive 1995

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

Search the Archive

Re: I'm looking for an algorithm: Cartesian Product


In article <3ti27l$klt at news0.cybernetics.net>,
Hala Skaf <Hala.Skaf at loria.fr> wrote:
>
>Hello,
>
>     I'm looking for an algorithm that can compute 
> Cartesian Product for several sets. For example:
>
> How can I compute the Cartesian Product of:
>
>	E1={a1 a2} E2={b1 b2 b3} E3={z1 z2}
>
In[3]:=
    Outer[List, {a1, a2}, {b1, b2, b3}, {z1, z2}]
Out[3]=
    {{{{a1, b1, z1}, {a1, b1, z2}}, 
       {{a1, b2, z1}, {a1, b2, z2}}, 
       {{a1, b3, z1}, {a1, b3, z2}}}, 
      {{{a2, b1, z1}, {a2, b1, z2}}, 
       {{a2, b2, z1}, {a2, b2, z2}}, 
       {{a2, b3, z1}, {a2, b3, z2}}}}

In[4]:=
    Flatten[%, 2]
Out[4]=
    {{a1, b1, z1}, {a1, b1, z2}, {a1, b2, z1}, 
      {a1, b2, z2}, {a1, b3, z1}, {a1, b3, z2}, 
      {a2, b1, z1}, {a2, b1, z2}, {a2, b2, z1}, 
      {a2, b2, z2}, {a2, b3, z1}, {a2, b3, z2}}

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon


  • Prev by Date: Re: Download from Mathsource
  • Next by Date: Re: Options in self-defined functions
  • Previous by thread: I'm looking for an algorithm: Cartesian Product
  • Next by thread: Re: I'm looking for an algorithm: Cartesian Product