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 > Rearranging & Restructuring Lists >
Mathematica > Data Manipulation > Handling Arrays of Data > Rearranging & Restructuring Lists >

Gather

Gather[list]
gathers the elements of list into sublists of identical elements.
Gather[list, test]
applies test to pairs of elements to determine if they should be considered identical.
  • The default function used to test whether elements are identical is SameQ.
  • Gather[{e1, e2, ...}, p] will gather together elements for which p[ei, ej] returns True.
Gather multiple solutions together:
Gather elements that have equal integer parts:
Gather integers that have identical remainders:
Gather polynomials that have identical remainders:
Check the remainders in each list:
Gather multiple solutions together:
In[1]:=
Click for copyable input
Out[1]=
 
Gather elements that have equal integer parts:
In[1]:=
Click for copyable input
Out[1]=
 
Gather integers that have identical remainders:
In[1]:=
Click for copyable input
Out[1]=
 
Gather polynomials that have identical remainders:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Check the remainders in each list:
In[3]:=
Click for copyable input
Out[3]=
DeleteDuplicates[list] is equivalent to Gather[list][[All, 1]]:
For a large list, DeleteDuplicates is much faster:
GatherBy[list, f] is equivalent to Gather[list, (f[#1]SameQf[#2])&]:
Gather the rows by Norm and display with the common norm of each group:
Compare to the result of Gather:
When the test cannot be identified as a equality comparison, Gather may be much slower:
The results are identical:
New in 7
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team