Mathematica 9 is now available

Partition

Partition[list, n] partitions list into nonoverlapping sublists of length n.
Partition[list, n, d] generates sublists with offset d.
Partition[list, { ,  , ... }] partitions a nested list into blocks of size  .
Partition[list, { ,  , ... }, { ,  , ... }] uses offset  at level i in list.
Partition[list, n, d, { ,  }] specifies that the first element of list should appear at position  in the first sublist, and the last element of list should appear at or after position  in the last sublist. If additional elements are needed, Partition fills them in by treating list as cyclic.
Partition[list, n, d, { ,  }, x] pads if necessary by repeating the element x.
Partition[list, n, d, { ,  }, { ,  , ... }] pads if necessary by cyclically repeating the elements  .
Partition[list, n, d, { ,  }, {}] uses no padding, and so can yield sublists of different lengths.
Partition[list, nlist, dlist, { ,  }, padlist] specifies alignments and padding in a nested list.

• Example: Partition[{a, b, c, d, e, f}, 2] LongRightArrow  .
• All the sublists generated by Partition[list, n, d] are of length n. Some elements at the end of list may therefore not appear in any sublist.
• The element e in Partition[{a, b, c, d, e}, 2] LongRightArrow  is dropped.
Partition[{a, b, c, d, e}, 3, 1] LongRightArrow  generates sublists with offset 1.
• All elements of list appear in the sublists generated by Partition[list, n, 1].
• If d is greater than n in Partition[list, n, d], then elements in the middle of list are skipped.
Partition[list, 1, d] picks out elements in the same way as Take[list, {1, -1, d}].
Partition[list, n, d, { ,  }] effectively allows sublists that have overhangs that extend past the beginning or end of list.
Partition[list, n, d, k] is equivalent to Partition[list, n, d, {k, k}].
• Common settings for { ,  } are:

{1, -1}        allow no overhangs
(1, 1}        allow maximal overhang at the end
{-1, -1}        allow maximal overhang at the beginning
{-1, 1}        allow maximal overhangs at both beginning and end

• Example: Partition[{a, b, c, d}, 2, 1, {-1, 1}] LongRightArrow  .
Partition[list, n, d, { ,  }, padlist] effectively lays down repeated copies of padlist, then superimposes one copy of list on them, and partitions the result.
• Common settings for padlist are:

x            pad with repetitions of a single element
{ ,  , ... }        pad with cyclic repetitions of a sequence of elements
list            pad by treating the list as cyclic (default)
{}            do no padding, potentially leaving sublists of different length

• Examples: Partition[{a, b, c, d}, 2, 1, {-1, 1}, {x, y}] LongRightArrow  .
Partition[{a, b, c, d}, 2, 1, {-1, 1}, {}] LongRightArrow  .
Partition[list, { ,  , ... ,  }] effectively replaces blocks of elements at level r in list by depth r nested lists of neighboring elements.
• If no offsets are specified, the neighborhoods are adjacent and nonoverlapping.
Partition[list, { ,  , ... }, d] uses offset d at every level.
Partition[list, nlist, dlist, {{ ,  , ... }, {{ ,  , ... }}] specifies that element {1, 1, ... } of list should appear at position { ,  , ... } in the {1, 1, ... } block of the result, while element {-1,-1, ... } of list should appear at or after position { ,  , ... } in the {-1, -1, ... } block of the result.
{ ,  } is taken to be equivalent to {{ ,  , ... }, { ,  , ... }}.
{{ ,  , ... }} is taken to be equivalent to {{ ,  , ... }, { ,  , ... }}.
Partition[list, { ,  , ... ,  }, klist, padlist] effectively makes a depth r array of copies of padlist, then superimposes list on them and partitions the result.
• See also:
Flatten, Take.

Examples

Using InstantCalculators

Here is the InstantCalculator for the Partition function. Enter the parameters for your calculation and click Calculate to see the result.

Entering Commands Directly

You can paste a template for this command via the Text Input button on the Partition Function Controller.

This groups the elements of the original list in pairs; the seventh is thrown away.

This makes triples of elements, with each successive triple offset by just one element.



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.