Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
42 views

How to SortBy Min[Last]

I have a list of the form { {1, {3., ∞, ∞, ∞}}, {2, {1.,1., ∞, ∞}}, {3, {0.333333, 0.666667, ∞, ∞}} } and I would like to sort it by the minimal of the nested ...
1
vote
1answer
42 views

Sort and extract values in a nested list

I want to sort the following nested list of peak points by the y values while keeping the dimensions consistent. I then want to extract the x value of the largest and second largest y values (if the ...
4
votes
1answer
69 views

How to sort by subscript

I notice that ...
3
votes
2answers
76 views

Sorting a Collection of Lists by Comparing Different Parts

I am looking for a way to use Sort[] to sort a collection of lists by comparing different parts of these lists. For example, sorting by comparing the second part of ...
2
votes
1answer
108 views

list sorting task

I am trying to understand how to sort by multiple columns in Mathematica. Here is a simple data set consisting of results of sports matches. Each element represents a game, and contains fields for ...
0
votes
1answer
39 views

Sorting a list according to the position of elements

I have a list of elements, which I want to sort according to the even/odd numbered positions of elements. Basically creating two lists out of one, respectively having elements placed at even/odd ...
7
votes
4answers
493 views

Find elements of array with largest absolute value

I am wondering how to do in Mathematica the following: Given as an input a large array, I want to output a list of top $n$ entries with largest absolute value + their location within the array. ...
5
votes
1answer
63 views

Sort Data Sets by Lines/Neighbours

I have several sets of data which together yield Fig. 1. As can be seen from the colours of the dots, the data sets are mixed, but do obviously belong to several distinct lines. My question is: How ...
0
votes
0answers
50 views

Using SortBy on a list of a list of a list

I have quite a typical physics problem at hand, I want the eigenvalues and -vectors of a Hamiltonian matrix. I have a parameter s, which I vary in 1000 steps and for each step I want my H matrix to be ...
7
votes
2answers
180 views

Sorting sequences independent of color

I have two lists $R$ and $B$ of numbers written in red and blue. I would like to join those two lists and reorder them in increasing order to get a visual feeling of how both sequences are distributed....
5
votes
1answer
65 views

Why do these commands give different answers?

I'm using v12 ...
5
votes
2answers
165 views

Canonical ordering of days of week

The entities representing the days of the week sort alphabetically: ...
2
votes
1answer
72 views

Sort Dataset by Row index after GroupBy

I would like to sort my Dataset by its row index. Unlike an ordinary column, this index does not have a name. ...
5
votes
3answers
87 views

Sort Associations by its Values (which are nested lists)

I have associations where the values are nested lists: ...
5
votes
2answers
487 views

Ordering a list of integers

I have a list of integers which I am trying to order in the following way: remove all zeros from the list sort in increasing order of absolute value put positive values before negative values I.e. ...
3
votes
2answers
118 views

Group symbols by a given partition of the occuring symbols

I have following expression $$-3 b_{\sigma _d}-3 b_{\sigma _v}-b-b_2+2 j-2 j_2-2 j_3+2 j_6+12$$ Mathematica input ...
3
votes
1answer
80 views

Sorting a list into “all possible ways” - sorting with incomplete information

Familiar example of sorting objects I have a list of $n$ "vectors" $\{x^{(1)},...,x^{(n)}\}$ of form $ x^{(i)}=\sum_{j=1}^m c_j^{(i)}x_j,i=1\dots n$, where $c_j^{(i)}$ are nonnegative ...
3
votes
2answers
268 views

Derivative of Sort

I want to calculate gradient of Sort[{x1,x2,x3,x4}] but it seems like I'm getting a wrong answer. Specifically ...
5
votes
2answers
118 views

How to show just one function from a stored plot?

Q: Is there a general way to remove particular functions from a previously stored call to a plot function? Here is a specific example: ...
6
votes
3answers
246 views

Sorting a list according to some pre-specified rules

Given a list such as {12,9,3,42,30,10,11,1,2} I would like to place only the multiples of 3 in the natural order without changing the order of the other ...
4
votes
2answers
194 views

Sort a list of lists by increasing order of elements [closed]

What is the quickest way to sort a list of lists of integers, such that the first sorting criterion is the first element of the list, the next is the second element of the list and so on? E.g. The ...
2
votes
4answers
93 views

Sorting polynomials based on their y value and finding their intersection

I've got the following list of polynomials, ...
5
votes
2answers
220 views

Lowest Magnitude Eigenvalues of Large Sparse Matrices

I am trying to find the first three lowest eigenvalues of large sparse matrices of size range $10^3 - 10^5$. The matrices depend on some parameter $x$, so I first construct the matrices and then use ...
11
votes
1answer
1k views

Why does Sin[b-a] simplify to -Sin[a-b]?

As I understand it, Mathematica often uses alphabetical order when simplifying expressions. For example, b-a simplifies to -a+b. ...
1
vote
1answer
42 views

How to sort the “do” output?

So I have function (FindCoefficients) that iterates through some values to find the maximum value for a function. It is much quicker to hold the non-linear values constant and do a find maximum for ...
6
votes
2answers
171 views

Sorting upon the first element of a nested list and show that as numerical values

I wish to sort the below list upon the first elements: ...
1
vote
0answers
87 views

how to sort an expression with descending coefficients?

I have an expression for example psi = 0.24 FF1[0] FF2[1] FF3[-1] + 0.23 FF1[0] FF2[0] FF3[1] + 0.5 FF1[1] FF2[0] FF3[1] + 0.25 FF1[1] FF2[1] FF3[1] I wonder how ...
1
vote
1answer
59 views

Sorting each column in a nested list contained in an association

I have an Association which contains three arrays 200x1000x2. Each row m of a matrix denotes a different set of parameters, while each column n contains the outcomes of the function for a specific ...
4
votes
1answer
86 views

AlphabeticSort of Chinese character is not working now

I want to sort strings of chinese characters. I used to use below code list={"大家","早上","好"}; AlphabeticSort[list, Entity["Language", "ChineseMandarin"]] And it ...
14
votes
1answer
434 views

ls Ordering[Ordering[list]] optimal?

Given a list list with unique elements, the task is to replace each element by its position in Sort[list]. For example, ...
2
votes
1answer
113 views

How can I animate the sorting by Sort, BarChart and Animate? [duplicate]

I try to make an animation of sorting like this but something goes wrong. ...
8
votes
3answers
486 views

Sort a list by elements of another list

I know there are a plenty of other questions here which appear to be similar, however I did not found anything which could give me a hint. I have two lists: ...
14
votes
3answers
365 views

Terse Method to Swap Lowest for Highest?

I have built a solution to swap the lowest values with the highest values in a list. With ...
6
votes
4answers
540 views

Sort with assumptions

I have a list which looks like this list = {0, Subscript[x,7], -Subscript[x,3]-Subscript[x,9], -Subscript[x,9]}; and all the $x_i$'s are positive semidefinite (i....
1
vote
1answer
48 views

Inconsistency in SortBy [duplicate]

I have a list of data, I tried to SortBy it in two equivalent way, but the result is different. The data variable is something ...
1
vote
1answer
55 views

Sort the data in the given way

Consider the data data = {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},{x4,y4,z4},{x5,y5,z5},{x6,y6,z6},...} with N rows. It can be divided into N/3 sets of 3 rows. I would ...
4
votes
2answers
188 views

how to sort the expression not based on the Heads in Times?

Is there any way i can sort the following expression ? a[k, l] b[i, j] so that i would have: b[i, j] a[k,l] Mathematica ...
2
votes
1answer
153 views

Function for SortBy

Let's say I have the following list ...
3
votes
1answer
135 views

Sorting of a list with different lengths

I have a list of disordered numbers. They are collected in different lists. I mean ...
3
votes
2answers
257 views

Outputting expressions in the order in which they're entered

Background For display purposes, I sometimes find it desirable to defeat Mathematica's canonical ordering of variables, and instead have it output terms in the order in which I type them. E.g., ...
2
votes
1answer
86 views

how to sort a list without build-in function

I want to sort a list like below.Without using the build-in function so I tried this: ...
7
votes
4answers
529 views

Sorting a list while keeping its correspondence to another list

I have the following two lists: ...
2
votes
2answers
316 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
315 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
218 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
223 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
43 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
825 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
53 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
209 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 2 3 4 5 6