Search for all pages containing Partition
Partition
✖
Partition
specifies that the first element of list should appear at position kL in the first sublist, and the last element of list should appear at or after position kR in the last sublist. If additional elements are needed, Partition fills them in by treating list as cyclic.
specifies alignments and padding in a nested list.
Details



- 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.
- Partition[list,UpTo[n]] partitions into sublists of length up to n, allowing the final sublist to be shorter.
- 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. »
- Sublist lengths can always be specified as UpTo[n], in which case shorter sublists can be returned if fewer than n elements are available.
- Partition[list,n,d,{kL,kR}] 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 {kL,kR} 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 - Partition[list,n,d,{kL,kR},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 {x1,x2,…} pad with cyclic repetitions of a sequence of elements list pad by treating list as cyclic (default) {} no padding, potentially leaving sublists of different lengths - If list has length s, then Partition[list,n,d] yields Max[0,Floor[(s+d-n)/d]] sublists.
- Partition[list,{n1,n2,…,nr}] 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,{n1,n2,…},d] uses offset d at every level.
- Partition[list,nlist,dlist,{{kL 1,kL 2,…},{kR 1,kR 2,…}}] specifies that element {1,1,…} of list should appear at position {kL 1,kL 2,…} in the {1,1,…} block of the result, while element {-1,-1,…} of list should appear at or after position {kR 1,kR 2,…} in the {-1,-1,…} block of the result.
- {kL,kR} is taken to be equivalent to {{kL,kL,…},{kR,kR,…}}.
- {{k1,k2,…}} is taken to be equivalent to {{k1,k2,…},{k1,k2,…}}.
- Partition[list,{n1,n2,…,nr},klist,padlist] effectively makes a depth-r array of copies of padlist, then superimposes list on them and partitions the result.
- If list has dimensions {s1,s2,…,sr}, then Partition[list,{n1,n2,…,nr}] will have dimensions {q1,q2,…,qr,n1,n2,…,nr}, where qi is given by Floor[si/ni].
- The object list need not have head List. »
- Partition can be used on SparseArray objects.
Examples
open allclose allBasic Examples (6)Summary of the most common use cases
Partition into sublists of length 2:

https://wolfram.com/xid/0bn6cgi-lp3

Partition into sublists of length 3 with offset 1:

https://wolfram.com/xid/0bn6cgi-h01

Partition a two-dimensional array into 2×2 blocks with offset 1:

https://wolfram.com/xid/0bn6cgi-wr6

Allow the last list to be shorter than the others:

https://wolfram.com/xid/0bn6cgi-f25w6u


https://wolfram.com/xid/0bn6cgi-kttom9

Start with the first element at the end of the first partition:

https://wolfram.com/xid/0bn6cgi-6iqln9

Partition with padding on the left:

https://wolfram.com/xid/0bn6cgi-ro49q1


https://wolfram.com/xid/0bn6cgi-m3ytl6


https://wolfram.com/xid/0bn6cgi-zlou4s


https://wolfram.com/xid/0bn6cgi-1srtkz

Scope (18)Survey of the scope of standard use cases
Padding (7)
Incomplete sublists at the end are by default dropped:

https://wolfram.com/xid/0bn6cgi-yko


https://wolfram.com/xid/0bn6cgi-jzz

Allow for a "ragged" partition, wherein last elements can be shorter:

https://wolfram.com/xid/0bn6cgi-gc1gv8


https://wolfram.com/xid/0bn6cgi-7zs1b


https://wolfram.com/xid/0bn6cgi-dfw


https://wolfram.com/xid/0bn6cgi-xnz

Pad by repeating {x,y,z} blocks:

https://wolfram.com/xid/0bn6cgi-urh

Use no padding, so later sublists can be shorter:

https://wolfram.com/xid/0bn6cgi-glo

Pad with Nothing to achieve the same result:

https://wolfram.com/xid/0bn6cgi-l2xbre

Partition from the end and use no padding:

https://wolfram.com/xid/0bn6cgi-fkvp25

Padding Alignment (6)

https://wolfram.com/xid/0bn6cgi-nvt

Insert padding at the beginning:

https://wolfram.com/xid/0bn6cgi-c3i


https://wolfram.com/xid/0bn6cgi-yp6


https://wolfram.com/xid/0bn6cgi-u73

Make the input start at position 2 in the first sublist, and end at position 1 in the last sublist:

https://wolfram.com/xid/0bn6cgi-fwq

Pad by laying down repeating copies of {x,y}:

https://wolfram.com/xid/0bn6cgi-da1

Multidimensional Arrays (5)

https://wolfram.com/xid/0bn6cgi-hpe


https://wolfram.com/xid/0bn6cgi-jm7

Partition into 2×2 blocks with offset 1, padding at the ends of rows and columns with xx:

https://wolfram.com/xid/0bn6cgi-fp3


https://wolfram.com/xid/0bn6cgi-n60

Partition into 2×2 blocks with offset 1, taking the array to be cyclic in both dimensions:

https://wolfram.com/xid/0bn6cgi-egq


https://wolfram.com/xid/0bn6cgi-lii

Insert padding at the beginnings of columns and the beginnings and ends of rows:

https://wolfram.com/xid/0bn6cgi-rwu

Pad the beginnings and ends of columns and the ends of rows:

https://wolfram.com/xid/0bn6cgi-yy5

Generalizations & Extensions (4)Generalized and extended use cases
Skip elements by using an offset larger than the block size:

https://wolfram.com/xid/0bn6cgi-yiv

Padding can be longer than the block size:

https://wolfram.com/xid/0bn6cgi-jla

The head need not be List:

https://wolfram.com/xid/0bn6cgi-zc3

Partition works with SparseArray objects:

https://wolfram.com/xid/0bn6cgi-isk

Applications (5)Sample problems that can be solved with this function
Partition to lay out a list in 2D:

https://wolfram.com/xid/0bn6cgi-haa

Find pairs of successive elements in a list:

https://wolfram.com/xid/0bn6cgi-jqo

Find successive ratios in a list:

https://wolfram.com/xid/0bn6cgi-x2a


https://wolfram.com/xid/0bn6cgi-qj4

Implement an elementary cellular automaton:

https://wolfram.com/xid/0bn6cgi-xe1


https://wolfram.com/xid/0bn6cgi-jsk

Partition a flat list of elements into a multidimensional array with specified dimensions:

https://wolfram.com/xid/0bn6cgi-cl2lmr

https://wolfram.com/xid/0bn6cgi-bxhb8i

Create a multidimensional array of successive integers:

https://wolfram.com/xid/0bn6cgi-d5fc7t


https://wolfram.com/xid/0bn6cgi-eek6c4

Properties & Relations (3)Properties of the function, and connections to other functions
Flatten is essentially the inverse of Partition:

https://wolfram.com/xid/0bn6cgi-mzl


https://wolfram.com/xid/0bn6cgi-r0e

The sublists in the result of Partition have the same length:

https://wolfram.com/xid/0bn6cgi-eyyksd

UpTo allows having a shorter list at the end:

https://wolfram.com/xid/0bn6cgi-dd0uv2

TakeList allows specifying the lengths of the sublists:

https://wolfram.com/xid/0bn6cgi-qmkxl3

ListCorrelate[ker,list] effectively combines ker with a partitioned list:

https://wolfram.com/xid/0bn6cgi-h2952w

https://wolfram.com/xid/0bn6cgi-crp1zf

Partition the list into segments the length of ker with offset 1:

https://wolfram.com/xid/0bn6cgi-drm5ew

Use Dot to combine the kernel with each segment:

https://wolfram.com/xid/0bn6cgi-k7hn1d

ListConvolve is similar except the kernel is reversed:

https://wolfram.com/xid/0bn6cgi-bqi6y


https://wolfram.com/xid/0bn6cgi-gti9a

Wolfram Research (1988), Partition, Wolfram Language function, https://reference.wolfram.com/language/ref/Partition.html (updated 2015).
Text
Wolfram Research (1988), Partition, Wolfram Language function, https://reference.wolfram.com/language/ref/Partition.html (updated 2015).
Wolfram Research (1988), Partition, Wolfram Language function, https://reference.wolfram.com/language/ref/Partition.html (updated 2015).
CMS
Wolfram Language. 1988. "Partition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Partition.html.
Wolfram Language. 1988. "Partition." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Partition.html.
APA
Wolfram Language. (1988). Partition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Partition.html
Wolfram Language. (1988). Partition. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Partition.html
BibTeX
@misc{reference.wolfram_2025_partition, author="Wolfram Research", title="{Partition}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Partition.html}", note=[Accessed: 17-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_partition, organization={Wolfram Research}, title={Partition}, year={2015}, url={https://reference.wolfram.com/language/ref/Partition.html}, note=[Accessed: 17-March-2025
]}