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

Questions tagged [sorting]

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

2
votes
2answers
97 views

Inserting an integer into a sorted list

I'm wondering if inserting an integer into a sorted list (in a way that the list remains sorted) can be performed in Mathematica in some fancy way in $\log(N)$ time?.. The question was asked here, ...
3
votes
2answers
303 views

What is the Alphabetical Inequality Test?

Mathematica can sort {"b","d","a","c"} into {"a","b","c","d"} with a simple application of ...
5
votes
2answers
195 views

How can I order this list on mathematica?

This is my list Matrix = {{1, -2, 3, -4}, {{a, b}, {f, e}, {a, b}, {f, e}}} I want to order the columns in ascending order depending on the values on the first ...
12
votes
1answer
206 views

OrderedQ with string arguments

I don't find these results consistent: OrderedQ[{"a", "A"}] True OrderedQ[{"a2", "A1"}] False Is there any ...
0
votes
1answer
35 views

How to assume lexicographical ordering

Suppose I have functions which depends on the symbols $c[I]$, where $I$ is some subset of $\{1,2,...,n\}$. For example, $$f = c[1] + c[1,2,3] + c[1,2],$$ $$g = c[2] + c[2,1],$$ Code: ...
15
votes
6answers
776 views

Better way to sort course grades

I use the following code to create a histogram of grades. Grades are provided as a List of strings such as "A-", "D+", "E" (don't ask), etc. The +/- substitution hack is necessary to sort the grades ...
1
vote
0answers
37 views

In what order does Combinatorica's SetPartitions function list the partitions of a set?

For example, Needs["Combinatorica`"] n = 4; partitions = SetPartitions[Range[n]]; Table[Print[partitions[[i]]], {i, 1, BellB[n]}] generates ...
2
votes
2answers
52 views

Nested sorting of lists

I have the following list representing a custom set of cards: Each card is represented by a list of two elements, like this: {heart,9} Using the code: ...
1
vote
3answers
54 views

Sorting out list elements that are nonlinear in a certain function

I have the following (long) list (exemplary I will show you only a few elements of it): ...
11
votes
1answer
113 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
40 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
56 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
161 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
41 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
5
votes
1answer
54 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
12 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
56 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
71 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
339 views

Simple method to sort versions

The goal is to sort long lists of versions. For example: Input ...
0
votes
1answer
39 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
46 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
26 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
154 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
36 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
55 views

Feyncalc remove higher-order TensorFunction terms from expression

I am looking for a way to reduce the following expression: ...
5
votes
2answers
152 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
179 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
54 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
50 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
56 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
319 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
30 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
515 views

How to SortBy Last and in Reverse order?

I am looking at the two functions SortBy and ReverseSort. ...
1
vote
1answer
35 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
38 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
39 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
128 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
58 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
98 views

Sort List of Rules in Numeric Order

I have a list of rules, ...
6
votes
2answers
88 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
90 views

Ordering elements of a list

Let's define some simple functions ...
2
votes
0answers
34 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
93 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
142 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
83 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
510 views

Synchronize lists

I have two 2d lists: ...
4
votes
1answer
123 views

Sorting a list of rules

When we give several definitions for a function f, the DownValues of f are automatically ...