Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > List Manipulation > Constructing Lists >
Mathematica > Data Manipulation > Handling Arrays of Data > Constructing Lists >

Tuples

Tuples[list, n]
generates a list of all possible n-tuples of elements from list.
Tuples[{list1, list2, ...}]
generates a list of all possible tuples whose i^(th) element is from listi.
  • The elements of list are treated as distinct, so that Tuples[list, n] for a list of length k gives output of length kn.
  • The order of elements in Tuples[list, n] is based on the order of elements in list, so that Tuples[{a1, ..., ak}, n] gives {{a_1,a_1,...,a_1},{a_1,a_1,...,a_2},...,{a_k,a_k,...,a_k}}.
  • Tuples[list, {n1, n2, ...}] generates a list of all possible n_1xn_2x... arrays of elements in list.
  • The object list need not have head List. The head at each level in the arrays generated by Tuples will be the same as the head of list.
All possible 3-tuples of 0 and 1:
The first element given is always picked first:
All ways of picking one element from each list:
All possible 3-tuples of 0 and 1:
In[1]:=
Click for copyable input
Out[1]=
 
The first element given is always picked first:
In[1]:=
Click for copyable input
Out[1]=
 
All ways of picking one element from each list:
In[1]:=
Click for copyable input
Out[1]=
Each occurrence of an element is picked separately:
All possible 2×2 arrays formed from a and b:
Tuples with any head:
Digits of successive base-2 numbers:
All possible trigrams of A and B:
Neighborhood rules for an elementary cellular automaton:
Digit sequences, or evolution of a substitution system:
2D lattice of points:
Connect pairs of points in all possible ways:
All possible digit sequences:
Results from Outer involve extra sublists:
Subsets picks each element at most once, and treats reorderings as equivalent:
With one argument, Tuples picks an element from each sublist:
With two arguments, Tuples treats each sublist as a complete element:
3D lattice of points:
New in 5.1
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team