Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see:

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see:

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see:

added 40 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see: Sort data after specific ordering (ascending/descending) in multiple columns for further ideas.

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see: Sort data after specific ordering (ascending/descending) in multiple columns for further ideas.

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see:

deleted 2 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{ccc} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see: Sort data after specific ordering (ascending/descending) in multiple columns for further ideas.

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{ccc} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see: Sort data after specific ordering (ascending/descending) in multiple columns for further ideas.

This is implemented in SortBy:

Mathematica graphics

Because this function does not perform a pairwise compare, you would need to be able to recast your sort function to produce a canonical ordering. On the upside, if you are able to do so it will be far more efficient than Sort.

f1 = Mod[#, 4] &;
f2 = Mod[#, 7] &;

SortBy[Range@10, {f1, f2}]

{#, f1@#, f2@#} & /@ % // Grid
{8, 4, 1, 9, 5, 2, 10, 6, 7, 3}

$\begin{array}{r} 8 & 0 & 1 \\ 4 & 0 & 4 \\ 1 & 1 & 1 \\ 9 & 1 & 2 \\ 5 & 1 & 5 \\ 2 & 2 & 2 \\ 10 & 2 & 3 \\ 6 & 2 & 6 \\ 7 & 3 & 0 \\ 3 & 3 & 3 \end{array}$

Also see: Sort data after specific ordering (ascending/descending) in multiple columns for further ideas.

added 354 characters in body; added 65 characters in body; added 19 characters in body; added 84 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k
Loading