MathGroup Archive 2005

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

Search the Archive

Re: direct product of two sets


Hello Cong,

There are two methods that come to mind:

In[1]:=  A={1, 2, 3};
In[2]:=  B={x, y, z};

In[3]:= Tuples[{A, B}]
Out[3]= {{1, x}, {1, y}, {1, z}, {2, x}, {2, y}, {2, z}, {3, x}, {3, y}, 
{3, z}}

Note that Tuples is a new function introduced in Version 5.1.

In[4]:= Flatten[Outer[List, A, B, 1], 1]
Out[4]= {{1, x}, {1, y}, {1, z}, {2, x}, {2, y}, {2, z}, {3, x}, {3, y}, 
{3, z}}

Other short programs will do this too, but I think these are the shortest.

Best wishes,

Richard Phillips
Wolfram Research

ps.
http://mathworld.wolfram.com/CartesianProduct.html
http://mathworld.wolfram.com/DirectProduct.html


  • Prev by Date: LaplaceTransform TraditionalForm symbol
  • Next by Date: Re: NewBie question Plot Table of points from a data file
  • Previous by thread: Re: direct product of two sets
  • Next by thread: Strange bug