Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
4
votes
1answer
101 views

Sorting exponential numbers

I want to sort some exponential numbers like {2^2,3^3,4^2} and i want The result {2^2,4^2,3^3}. But Mathematica Sort function apply's the powers in the result and return's {4,16,27}. How can i get the ...
0
votes
0answers
28 views

How to sort a distance matrix in mathematica

I have the following code which results in the heatmap shown: ...
2
votes
1answer
67 views

Unique matrix ID and fast checking

I have the following problem : I have a programm which can generate a lot of 3x3 matrices whose elements take integer values in [-3;3], example :{{1,2,3},{-3,0,-2},{1,1,1}}. Each time my programm ...
2
votes
3answers
115 views

Sorting a sparse matrix so that non-empty rows place on top

I have a $n$ by $2$ matrix that has binary values(0,1) as its entry. For example m={{1,Null},{Null,0},{Null,Null},{0,0},{1,0},{0,1}} I want it to be sorted ...
1
vote
1answer
36 views

Sort Stocks by MarketCap

If I correctly understand, here I have all the existing companies listed in every market and identified by each real name: ...
1
vote
0answers
45 views

Why doesn't Sort work in this case ? (Only numerical values)

Context I want to interpolate a complicated symmetric function f of 2 variables x and y defined by some numerical integral involving Bessel functions. Since computing the integral itself is a bit ...
0
votes
0answers
49 views

Help in modifying my code

In my code, I want to plot (Dis[t]). The problem is some functions containing in the code do not work well if there are variables in the form of symbols, such as "Sort" "NMaximize" functions. I want ...
0
votes
0answers
26 views

Preventing mathematica from evaluating “Sort” function, except in the case of numerical values

Say I want to sort the eigenvalues E1, E2, and E3 using "Greater" as following: {EA, EB} = Sort[{Chop[E1], Chop[E2], Chop[E3]}, Greater][[{1, 2}]]; But I want ...
0
votes
0answers
52 views

“Greater” function gives me wrong order

When I try to sort the eigenvalues of the matrix (Rho) the results seems to be in the wrong order What is wrong with my code? ...
-1
votes
1answer
24 views

Adding up a list of rules

Here's the problem: I take a count of a count, so that I end up with a list in this format: Table[Counts@Counts@Join[dKm[[i]], Pick[data1, ccKMedoid, i]], {i, 5}] ...
2
votes
1answer
40 views

Does Mathematica have an order relationship for lists, or a general ordering relation?

{1, 2} < {3, 4} doesn't seem to work, but Sort[{{3, 4}, {1, 2}}] yields {{1, 2}, {3, 4}}. ...
6
votes
4answers
213 views

Faster way to find longest chain of inequalities

I have a list of algebraic expression, all variables are positive, some of them have a specific size relationship. Such as: $\frac{(a b+a c+b c)^2}{a+b+c}\leq \frac{1}{3} (a+b+c) (a b+a c+b c)\leq \...
0
votes
2answers
32 views

Arrange exceptions in a list by some criteria

I have some dataset, which is supposed to have $30000$ in the last column, and I want to find the elements that break this, and arrange them numerically while mantaining the index. What I'm currently ...
2
votes
0answers
46 views

SortBy without final cannonical ordering

How can I SortBy a list without final cannonical ordering? E.g. SortBy[{9, 1, 2, 5, 3, 7}, # Boole[# >= 6] & ] returns <...
3
votes
1answer
173 views

Fast way of re-ordering list

I have a list which at each iteration of my algorithm is being modified. What I want to do is to find the elements that satisfy certain criterion (below it's simply being above the neighborhood ...
4
votes
1answer
162 views

How can we compare two strings?

In Python, you can do this: "ab" > "ac" which returns False. In Mathematica, it doesn't evaluate. But why? These are ...
6
votes
2answers
98 views

How to group points based on mesh primitive membership

As a simple example of what I want to do, let's say I have a Voronoi mesh in a $10\times10$ area with $10$ random "seed points": ...
8
votes
4answers
243 views

SortBy first element then second element, and so on?

SortBy can sort list by first element easily like so: SortBy[{{1, 6}, {1, 2, 8}, {2}}, First] and the result is: {{1, 6}, {...
4
votes
2answers
169 views

How can I sort a nested list?

I have a nested list of the form: ...
1
vote
1answer
32 views

Pick out two related elements from a list using criterion

Suppose I have a list: $lst= \{\{k_1, g_1\},\{k_2,g_2\},...,\{k_{max},g_{max}\},...,\{k_n,g_n\}\}$ Here $\{k_{max},g_{max}\}$ is a special element, in which $g_{max}$ is the maximum of all $g_{i}$ ...
2
votes
1answer
35 views

Matching list of eigenvalues and eigenvectors and removing negative values [closed]

I Have a matrix M (14x14) dimension in terms of variable k. Due to the complexity I wish to diagonalize M numerically as I can't symbolically. ...
3
votes
2answers
77 views

How to separate and re-order a list of points?

Suppose that we have a list of points. By plotting them we find two curves but the points are in a sequence of first fixing $x$ and then increasing $y$, next fixing $x+dx$ and then increasing $y$ and ...
1
vote
0answers
21 views

Canonical order for expressions that applied in Sort? [duplicate]

Sort[list] sorts the elements of list into canonical order. As an example for sorting expressions: Sort[{y, x^2, x + y, y^3}] ...
6
votes
3answers
68 views

Sorting list on multiple criteria based on means of subgroups

I have a set of records where each record is for a particular item. An item is a member of a particular subgroup and a subgroup is a member of a particular group. One item is always a member of a ...
3
votes
1answer
42 views

How do I order the solution of Solve?

How can I order the solutions of Solve from the one with the smallest real part to the one with the greatest real part?
3
votes
2answers
69 views
1
vote
1answer
43 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
47 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
75 views

How to sort by subscript

I notice that ...
3
votes
2answers
80 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
111 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
42 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
536 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
69 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
52 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
181 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
68 views

Why do these commands give different answers?

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

Canonical ordering of days of week

The entities representing the days of the week sort alphabetically: ...
2
votes
1answer
96 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
101 views

Sort Associations by its Values (which are nested lists)

I have associations where the values are nested lists: ...
5
votes
2answers
500 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
121 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
85 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
306 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
121 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
254 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
237 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
289 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
2 3 4 5
7