This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Ordering

Ordering[list]
gives the positions in list at which each successive element of Sort[list] appears.
Ordering
gives the positions in list at which the first n elements of Sort[list] appear.
Ordering
gives the positions of the last n elements of Sort[list].
Ordering
uses Sort.
  • In a numerical list Ordering gives the positions of the n smallest elements. Ordering gives the positions of the n largest elements.
  • If there are several smallest elements in list, Ordering will give only the position of the one that appears first.
  • is the same as Sort[list].
  • Ordering[list, All, p] gives the position at which all elements of list appear in Sort.
  • Ordering can be used on expressions with any head, not only List.
Find the ordering that sorts a list:
Apply the ordering:
Find the positions of the 4 smallest elements in a list:
Find the position of the largest element:
Find the ordering that sorts a list:
In[1]:=
Click for copyable input
Out[1]=
Apply the ordering:
In[2]:=
Click for copyable input
Out[2]=
 
Find the positions of the 4 smallest elements in a list:
In[1]:=
Click for copyable input
Out[1]=
 
Find the position of the largest element:
In[1]:=
Click for copyable input
Out[1]=
Find positions of elements from the 4^(th) smallest to the largest:
Find positions of elements in Sort[list, Greater]:
Use expressions with any head:
Find a permutation that sorts a list:
Apply the permutation:
Find the inverse of a permutation:
Sort a list of lists with respect to a particular position:
The same as Sort, but Ordering keeps the original ordering when elements are the same:
Using Ordering this way is much faster for large sets of lists:
Find the position of the maximum element:
is equivalent to Sort[list]:
New in 4.1