Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions on the sorting/ordering functions of Mathematica (Sort, SortBy, Ordering, etc.).

11
votes
1answer
78 views

stable sort for association?

Should I be able to use the "list of functions" approach to getting a stable sort of an association? In 11.1 I see, ...
1
vote
1answer
35 views

Import image files in the order of the file name number [duplicate]

I would like to import images which are frames from a video, they are numbered, so importing them in the correct order should not be a problem... However, when I import them, by writing: ...
1
vote
1answer
52 views

How to order a sum in ascending order of the powers? [closed]

Consider the sum x^1+x^3+x^2+x^4 I want to order this sum in such the I have the powers in ascending order x^1+x^2+x^3+x^4 ...
10
votes
1answer
111 views

Quick QuickSort implementation

I am playing with julialang and loving it, but at the same time noticed that they have a benchmark comparison with Mathematica. I have already submited a better version of ...
3
votes
2answers
37 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
5
votes
1answer
44 views

How to sort the data by several columns (some ascending and some descending)?

I have sorted the data firstly by the 3rd column and then by the 2nd column as below:- a = RandomInteger[20, {30, 3}] SortBy[a, {#[[3]], #[[2]]} &] As you ...
0
votes
0answers
10 views

Maintain written order in expression (lexicographic sorting rules) [duplicate]

Is there any way I can get output to follow the exact order that I wrote it? For instance (simple example) x = z + a - b + c^2 comes out as ...
4
votes
1answer
52 views

Sort images by difference

I can use ImageDistance to get the Euclidean distance between two images. But, I have list of (~100) images, and I want to sort them such that the average ...
1
vote
1answer
65 views

Why do I need a second Function in SortBy for Association?

I cannot understand why I need a second pure function when trying to sort Association by Key. Here is an example ...
6
votes
6answers
336 views

Simple method to sort versions

The goal is to sort long lists of versions. For example: Input ...
0
votes
1answer
31 views

Delete duplicates and sort a list of sets separately? [closed]

I have a set where it has three subsets. I want to have each element of each subsets appears only once, sorted, but the order of subsets does not change. For example: I want to get from $$ \{\{5,2,2,3\...
0
votes
0answers
37 views

SortBy not working in a delayed output

I have a table of large number of elements, each with three elements, say A = {{a, b, c}, {e, f, g}...}. I am using the function ...
0
votes
2answers
42 views

Sorting a table wrt to last two elements

I have a table-1 having 36 elements, each having the form {A, m, n}, where m & n are the indices (1-6). There is another table-2 having 36 elements {m, n} in a particular order (like {{4, 3}, {2, ...
0
votes
0answers
21 views

How can I get a specific ordering in the matrix and the results of a system linear equations?

I have a linear system of 22 equations and variables. When I create the matrix form it sorts the coefficients on the first row (X1, X10, X11, ...) This ordering repeats for all columns and all the ...
8
votes
1answer
151 views

How to find the position in original list ranked first by SortBy

SortBy is a wonder and convenient way to sort a list using a list of functions with which ties can be broken. ...
1
vote
1answer
34 views

Changing the display ordering of orderless functions?

If I write x = -(1 - 2 G M/r) \[DoubleStruckD]t^2 + (1 - 2 G M/r)^-1 \[DoubleStruckD]r^2 + r^2 \[DoubleStruckD]θ^2 + r^2 Sin[θ]^2 \[DoubleStruckD]ϕ^2; x I see ...
1
vote
1answer
53 views

Feyncalc remove higher-order TensorFunction terms from expression

I am looking for a way to reduce the following expression: ...
5
votes
2answers
137 views

How to replace columns of a matrix with an unsorted ordered list.

I have a matrix that I would like to replace the values of each column with where they are in an ordered list of values from least to greatest. For example, if I have ...
2
votes
2answers
106 views

How to sort ordered pairs by one coordinate with the other serving as tie-breaker [closed]

I have a collection of $N$ ordered pairs, $$\{\{x_{1},y_{1}\},\cdots,\{x_{N},y_{N}\}\}$$ These ordered pairs can have at most one entry in common, i.e., if $x_{i}=x_{j} \left(y_{i}=y_{j}\right)$ ...
0
votes
0answers
49 views

How to sort eigenvalues by eigenvector in a table [duplicate]

I'm trying to look at the evolution of the eigenvalues of a matrix as a function of magnetic field. My problem is that the eigenvectors are not ordered according to their eigenvector. I can sort these ...
2
votes
3answers
48 views

How can I generate a list of function calls in the sort order of values of the calls?

My problem is that I have a defined function, say, foo, and I am using the built in Sort function to order a sequence of calls <...
2
votes
1answer
43 views

How to sort string codes by their alpha and numeric tokens?

I have a large list of codes of the following form: codes = {"Fee.C21HJ.S4", "Fee.TOxC12.S1", "Fee.TOxC9.2 BB", "Fee.ROxC9.4", "Lag.C39"}; I would like to sort ...
2
votes
1answer
162 views

What is “standard” or “canonical” order? [duplicate]

When trying to sort a list of fractions and quadratic numbers I'm trying to work out why sort orders the quadratics after the fractions. It seems to use the function "OrderedQ" and "standard order" or ...
0
votes
1answer
28 views

Sort solutions obtained with the resolution of a system

After the resolution of a system of 4 equations, i obtained these solutions : ...
2
votes
2answers
80 views

Difference between (#1[[2]] < #2[[2]]&) and (#1[[2]] & < #2[[2]] &) [closed]

For example, if I have a list {{a, 2}, {c, 1}, {d, 3}} and I want to sort it w.r.t. the numbers: ...
8
votes
2answers
414 views

How to SortBy Last and in Reverse order?

I am looking at the two functions SortBy and ReverseSort. ...
1
vote
1answer
34 views

Reordering matrix variables with subscripts

I want to calculate a matrix product that preserves the ordering of variables as x then a then ...
0
votes
0answers
33 views

Sort the terms of expression by the given order?

Let's assume I have the following expression : D[K[x,y],{x,1}] + D[J[x,y],{x,2},{y,2}] + D[U[x,y],{x,2},{y,1}]. Can we sort it by the order corresponding to ...
0
votes
0answers
36 views

Evaluating multiple processes and sort the results

I would like to evaluate the code below and sort the two parameters {f2, M}. Say that i runs from 1 to 10 ...
6
votes
2answers
125 views

Creating lists within lists by sorting

I've been working with lists and am stuck on creating lists within a list based on the first element within that list. So for instance, if I have the list: ...
1
vote
1answer
55 views

MaximalBy in case of missing column entries

I have a large dataset, resulting from a JoinAcross operation, which looks similar like this one (only more complicated) ...
3
votes
1answer
81 views

Sort List of Rules in Numeric Order

I have a list of rules, ...
6
votes
2answers
82 views

Sorting elements in a table with respect to another table

I have two tables, each having three rows (R1, R2 & R3). The elements of R2 & R3 are same in two tables but in different orders. The elements in row R1 are different in two tables. I want to ...
0
votes
1answer
86 views

Ordering elements of a list

Let's define some simple functions ...
2
votes
0answers
30 views

Sort Voronoi cells by their generator points [duplicate]

When I create a Voronoi diagram from a set of generator points and then recover the cells through MeshPrimitives, the order of the cells does not match the order of ...
8
votes
0answers
90 views

What do the Internal`Compare* functions do?

As part of looking at this question I dug into Names["Internal`*Compare*"] and ended up with: ...
3
votes
2answers
128 views

Output all steps of Sort [duplicate]

Is there a way you output each partial result of the Sort function? i.e. Sort[{2,3,1}] {2,1,3} {1,2,3}
-1
votes
1answer
80 views

Extract part of list

I have the following list: {{{1, 0, 0}, {0.5, 1}}, {{2, 0, 0}, {0.5, 1}}, {{2, 0, 0}, {1, 1}}} I would like to take the first part if the second part get a ...
4
votes
4answers
492 views

Synchronize lists

I have two 2d lists: ...
3
votes
0answers
96 views

Sorting a list of rules

When we give several definitions for a function f, the DownValues of f are automatically ...
2
votes
1answer
52 views

How can i sort the bins within bin ranges?

i have following bins and binranges: ...
3
votes
1answer
333 views

Is there a way to sort NSolve solution (roots) automatically?

I had to run NSolve to solve nonpolinomial equation (it has some square roots in it) to get roots of the equation. I've got solution that looks something like this (see myrootsSolution). The ...
2
votes
2answers
79 views

Cyclically sort lists with some repeated elements? [duplicate]

This is a continuation of this question. In the previous question we got a routine that can take two cyclically equivalent lists and determine their equivalence if all the elements in each list are ...
14
votes
6answers
810 views

Rearrange the list in a specific way

Suppose I have a list like {"e", "c", "a", "d", "b"} and list of rules {1 -> 5, 2 -> 3, 3 -> 1, 4 -> 4, 5 -> 2}. ...
1
vote
1answer
62 views

Random order list of list

I have a dynamic PopupMenu defined as follow: ...
0
votes
3answers
177 views

Sort matrix rows and columns while keeping heading

I would like to sort columns and rows of a matrix in descending order by the sum of each row/column. However, my problem is that I cannot do so because I need to keep the heading of every column/row ...
1
vote
1answer
104 views

Sort using indices [closed]

I already know the sorted positions, so I want to sort based on that. Say, I have list of {1, 3}, I want the sorted position to be ...
1
vote
1answer
48 views

How to import several files at once according to a specific lexicographic order?

I tried with FileNames but it did not give me what im looking for. My files names are ...
2
votes
0answers
59 views

dynamic binary search

Suppose I have a time series of values $v_1, \dotsc, v_n, \dots,$ (think of the data as being generated by repeated function calls, like a Python generator, or being captured in real time) and I want ...