Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: direct product of two sets

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53315] Re: [mg53264] direct product of two sets
  • From: Richard Phillips <richardp at wolfram.com>
  • Date: Wed, 5 Jan 2005 01:21:50 -0500 (EST)
  • Organization: Wolfram Research
  • Sender: owner-wri-mathgroup at wolfram.com

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