Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
14
votes
3answers
210 views

Ordering Problem With VoronoiMesh

Imagine I want to model 2D cells moving in a tissue. Consider, as an example, Lloyd's relaxation algorithm. Using VoronoiMesh I'm able to mimic some cell movement. ...
0
votes
1answer
32 views

Sort a nested Association by another Association

I have a nested association of numerous pixel values sorted by sample date (e.g. 20190422C) and futher by a strain percentage (e.g. 0, 30, 50). I want to sort it even further using and Association of ...
4
votes
3answers
88 views

How do you reorder a sublist of strings, within a list?

I have a list that looks like this: ...
3
votes
3answers
378 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, ...
7
votes
2answers
190 views

Best way to insert element into an ordered list at the correct position?

Suppose I have an ordered list orderedList and I want to write some code that will involve regularly inserting new elements into ...
0
votes
2answers
26 views

Arranging terms by the values of numerical coefficients

I have a list with elements of the form myList = {c1 F1, c2 F2, c3 F3, ...} where c1, c2, ... are explicitly integers, and ...
0
votes
0answers
57 views

Resorting nested list A according to nested list B

How can sort nested list according to each other? e.g. I have the following list: ...
6
votes
1answer
107 views

How to group together numbers in a list by the value of their tens digit?

The line Table[Prime[n],{n,1000}] produces the list of first 1000 primes. Given this list how can the values be grouped by the values of their tens digit? i.e. how ...
2
votes
1answer
140 views

sorting eigenvectors of a final combined matrix

I have two matrices m1 and m2 as below: ...
3
votes
2answers
486 views

How can I sort the polynomial by the degree of $x$

f1 = a x^2 + b x + c + x^3 (* a x^2+b x+c+x^3 *) f1 /. x -> (x - a/3) // Expand (* (2 a^3)/...
4
votes
1answer
103 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
31 views

How to sort a distance matrix in mathematica

I have the following code which results in the heatmap shown: ...
2
votes
1answer
71 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
116 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
42 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
46 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 ...
6
votes
4answers
215 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
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
27 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
53 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
26 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
42 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}}. ...
3
votes
1answer
174 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 ...
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 <...
4
votes
1answer
179 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
100 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
248 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
181 views

How can I sort a nested list?

I have a nested list of the form: ...
4
votes
2answers
313 views
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
38 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
24 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
70 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
2answers
69 views
3
votes
1answer
54 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?
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
48 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
79 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 ...
4
votes
4answers
628 views
2
votes
1answer
112 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 ...
14
votes
1answer
311 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 ...
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
557 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
72 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
53 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 ...

1
2 3 4 5
7