Gather
Examples
open all close allBasic Examples (2)
Applications (3)
Gather elements that have equal integer parts:
Gather[Range[0, 3, 1 / 3], Floor[#1] == Floor[#2]&]Gather integers that have identical remainders:
Gather[Range[10], Mod[#1, 3] == Mod[#2, 3]&]Gather polynomials that have identical remainders:
data = Tuples[{0, 1}, 3].x ^ Range[0, 2];test = PolynomialRemainder[#1, 1 + x ^ 2, x] == PolynomialRemainder[#2, 1 + x ^ 2, x]&;Gather[data, test]Properties & Relations (2)
DeleteDuplicates[list] is equivalent to Gather[list][[All,1]]:
list = RandomInteger[20, 100];DeleteDuplicates[list]Gather[list][[All, 1]]For a large list, DeleteDuplicates is much faster:
big = RandomInteger[99, 10 ^ 7];
Map[First, {Timing[DeleteDuplicates[big]], Timing[Gather[big]]}]GatherBy[list,f] is equivalent to Gather[list,(f[#1]===f[#2])&]:
MatrixForm[m = RandomInteger[1, {10, 10}]]Gather the rows by Norm and display with the common norm of each group:
Grid[Map[{MatrixForm[#], Norm[First[#]]}&, gb = GatherBy[m, Norm]]]Compare to the result of Gather:
Gather[m, (Norm[#1] === Norm[#2])&] === gbPossible Issues (1)
When the test cannot be identified as an equality comparison, Gather may be much slower:
test1 = (Floor[#1] == Floor[#2])&;
test2[x_, y_] := Floor[x] == Floor[y];
r = RandomReal[10, 100000];Map[First, {Timing[g1 = Gather[r, test1]], Timing[g2 = Gather[r, test2]]}]g1 === g2Related Guides
History
Text
Wolfram Research (2008), Gather, Wolfram Language function, https://reference.wolfram.com/language/ref/Gather.html.
CMS
Wolfram Language. 2008. "Gather." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Gather.html.
APA
Wolfram Language. (2008). Gather. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Gather.html
BibTeX
@misc{reference.wolfram_2026_gather, author="Wolfram Research", title="{Gather}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/Gather.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_gather, organization={Wolfram Research}, title={Gather}, year={2008}, url={https://reference.wolfram.com/language/ref/Gather.html}, note=[Accessed: 13-June-2026]}