NumericalSort[list]
sorts the elements of list into numerical order.
NumericalSort
NumericalSort[list]
sorts the elements of list into numerical order.
Details
- NumericalSort[list] is equivalent to Sort[list,NumericalOrder].
- NumericalSort uses the same canonical order as Sort, except that it treats all numeric expressions, dates and Quantity objects by value, independent of their representation.
- NumericalSort can be used on expressions with any head, not only List.
Examples
open all close allBasic Examples (2)
NumericalSort[{1, Pi, E, Infinity, -Sqrt[2], -Infinity}]This may be different from the canonical expression order:
Sort[{1, Pi, E, Infinity, -Sqrt[2], -Infinity}]Groups of elements that can be compared with each other will typically be together in the result:
NumericalSort[{Now, TimeObject[], Infinity, Sqrt[2], -1, 0, -Infinity, Quantity[1, "Meters"], Quantity[3, "Feet"], TimeObject[{1, 23, 45}], DateObject[{1618, 3, 3, 9, 8, 8}]}]Scope (7)
-∞ comes before any real-valued expression, and ∞ comes after any real-valued expression:
NumericalSort[{2, Infinity, 0., -GoldenRatio, -Infinity, 1 / 3}]Sort arguments of any expression:
NumericalSort[data[0, 1, Infinity, -Infinity]]Sort associations by numerical value:
NumericalSort[<|a -> 0, b -> 1, c -> Infinity, d -> -Infinity|>]Sort expressions of the same head by numerical value:
NumericalSort[{h[0, 2], h[Infinity, 1], h[-Infinity, 3]}]Shorter expressions are sorted first:
NumericalSort[{h[0, 2, foo], h[Infinity, 1], h[-Infinity, 3]}]Complex-value expressions are sorted first by the real part and then by the absolute value of the imaginary part:
data = RandomSample@Flatten@Outer[Complex, Range[-1, 1], Range[-2, 2]]n = Length[data]ComplexListPlot[Thread[Callout[data, Range[n]]], ...]sdata = NumericalSort[data]ComplexListPlot[Thread[Callout[sdata, Range[n]]], ...]Sort quantities having compatible units:
NumericalSort[{Quantity[50, "Centimeters"], Quantity[0, "Meters"], Quantity[1, "Yards"], Quantity[2, "Feet"]}]If incompatible units are found, compatible units are grouped together:
NumericalSort[{Quantity[1, "Yards"], Quantity[1, "Minutes"], Quantity[50, "Centimeters"], Quantity[30, "Seconds"]}]NumericalSort[{Tomorrow, Today, Yesterday}]Properties & Relations (2)
NumericalSort uses NumericalOrder as ordering function:
NumericalSort[{b, a, Infinity, 0}]Sort[{b, a, Infinity, 0}, NumericalOrder]Using Less as ordering function also sorts numeric expressions, but not necessarily other expressions:
Sort[{b, a, Infinity, 0}, Less]The result of TakeSmallest is sorted following NumericalSort:
list = Sqrt /@ RandomInteger[100, 8]TakeSmallest[list, 8]% === NumericalSort[list]It can be different from the result of Sort:
Sort[list]Possible Issues (1)
NumericalSort will not guarantee a particular ordering for different representations of the same number:
list = {N[3, $MachinePrecision], 3, 3., N[3, 47]}NumericalSort[list]The canonical order will always rearrange in a definite way:
Sort[list]Related Guides
History
Text
Wolfram Research (2017), NumericalSort, Wolfram Language function, https://reference.wolfram.com/language/ref/NumericalSort.html.
CMS
Wolfram Language. 2017. "NumericalSort." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NumericalSort.html.
APA
Wolfram Language. (2017). NumericalSort. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NumericalSort.html
BibTeX
@misc{reference.wolfram_2026_numericalsort, author="Wolfram Research", title="{NumericalSort}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/NumericalSort.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_numericalsort, organization={Wolfram Research}, title={NumericalSort}, year={2017}, url={https://reference.wolfram.com/language/ref/NumericalSort.html}, note=[Accessed: 12-June-2026]}