Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
6
votes
1answer
81 views

Undesired side effect of SortBy [duplicate]

After long searching, I noticed that the SortBy[list,f] function has an annoying side effect: If the function f yields the same value for consecutive elements of the list, those are still sorted using ...
0
votes
1answer
46 views

How to obtain the grouped separate line curves from the disorder data?

The sample point data and codes are listed as following. The point-image tells us that the data can be divided into nine groups. However, why are they divided into two groups by ...
0
votes
1answer
56 views

Defining elements of matrix as a function of two variables (the position $(i,j)$ ) [closed]

I have the following array, which generated from grayscale image data,: $$ \left( \begin{array}{cccccccc} 162 & 162 & 162 & 161 & 162 & 157 & 163 & 161 \\ 162 & 162 &...
9
votes
1answer
252 views

On the ordering of the vertices of a polygon

Writing: pts = {{1, 0}, {2, 0}, {2, 3}, {3, 3}, {3, 4}, {0, 4}, {0, 3}, {1, 3}, {1, 0}}; Graphics[{Red, Point[pts], Blue, Line[pts]}] we get: and all of this ...
1
vote
0answers
37 views

Mismatch for Ordering[list,1] and Position[list, Min[list]] [closed]

I am using Ordering[list, 1] to get the position of the minimum of a list, but in this example ...
6
votes
3answers
155 views

Combine SortBy with ReverseSortBy

Suppose I have a dataset, which I want to sort according to two criteria. However, I want the first criteria to be sorted ascending, and the second descending. This would require to somehow combine ...
4
votes
1answer
96 views

how to sum a column after SortBy[…]

Given a dataset: ...
1
vote
1answer
48 views

l,r-operations on words $[[[1,2],3],4] \cdots, n]$, $[1,[2,[3,\cdots, [n-1,n]\cdots ]]]$

Suppose I have a word $\{1,2\}$, then $l(\{1,2\}) = \{[1,2]\} = \{1,2\} - \{2,1\}:=12-21$ and for the word with length $3$, (I will omit bracket), the $l$-operation is defined as $ l(1,2,3) = [[1,2],3]...
4
votes
1answer
72 views

Concise way to do lexicographic ordering

I want to order a bunch of number sequences lexicographically. Did this with ...
2
votes
1answer
22 views

ordered set inclusion 2

Slightly change the previous question, ordered set inclusion, Now, consider $A=\{2,3\}$ and $B=\{2,3,4,5\}, C=\{5,2,4,3\}$, Now I want to make element $\{2,3\}$ is in $B$ as well as $C$, what can be ...
2
votes
2answers
47 views

How to reorder {x,y} list data and plot as ListLinePlot

How to re-arrange data to find line plot in order (I tried with given below code). ...
1
vote
1answer
43 views

Sorting a Dataset by an enumerated column with assigned values

A $\mathtt{Dataset}$ has a column $C$ with enumerated values $c_i$, to each of which a number $n_{c_i}$ is manually assigned. The $\mathtt{Dataset}$ needs to be sorted based on the numbers. MWE: ...
6
votes
2answers
167 views

Stop Canonical Ordering of Output List

I'm working with the code below, which works well for my purposes; however, instead of the canonical ordering seen in the output, I want the output produced in the order I give in the Cases line of ...
1
vote
0answers
57 views

How can I sort in increasing order? [closed]

...
8
votes
6answers
269 views

How to sort and extract a list containing products

I've some difficulties with lists containing products as elements, e.g. list = {A B A, A K B, A K R}, where A and B are from the same 'family', let's call it sector ...
0
votes
1answer
86 views

How do I ensure the substitution happens after I take the first derivative before taking my second derivative

The title may be a little confusing so let me explain what I mean: I am using lagrange brackets to produce some equations of motion for orbital mechanics, where the motion is split between oscillating ...
5
votes
4answers
148 views
4
votes
2answers
178 views

How do I sort points {ai,bi}; i = 1,2,…,N so that immediate successors are closest?

Suppose there are points {ai,bi}; i = 1,....,N, but this is given in some jumbled order such as ...
-2
votes
1answer
50 views

Sorting of eigensystem accroding to specific eigenvector

I have a matrix, I want to sort it with respect to specific eigenvectors. Here, I provided an example of a matrix HT: ...
0
votes
0answers
15 views

How to reverse or restore the order of my cells in Wolfram Mathematica Cloud?

I was completing my assignment and I have no idea what I clicked but all the cells got reversed that is the 1st one on the last and the last is the first cell in my file. I want to restore it back. I ...
2
votes
2answers
66 views

Print function value at specified coordinate

Below is the code to evaluate the function. I am trying to print the function values at a specified coordinate as shown in ActCoor. ...
2
votes
1answer
100 views

Sorting Eigensystem According to Complicated Rule

I have looked for an answer to this but the near duplicates I could find seemed slightly distinct. I have a matrix $A$ which has eigenvalues in pairs $\lambda_1,-\lambda_1,\lambda_2,-\lambda_2,\dots$. ...
1
vote
1answer
40 views

sorting out the coordinate and respective solution values for plotting

I want to plot for coordinates and corresponding solution values below. ...
0
votes
2answers
78 views

How to select the median of a list?

If I have a list {3,19.5,85,45/2,5.6}, how can I select the median of the list without using the built-in Median command? First ...
1
vote
4answers
187 views

How would we extract elements of a list greater than a certain value? [closed]

Say we have a list {35,210,67,950,32,365} how would we extract all the elements greater than 100 from this list (using a function)? The desired output would be ...
1
vote
1answer
64 views

How to sort the list A in an increasing order, such that I can modify the other list B with change in element position of list A

I have two lists A and B, I am trying to change modify the elements of list A in an increasing order such that my list B should also be changed according to list A. The node no list is given below. <...
2
votes
2answers
108 views

Using iterative functions to specifically sort a list

The following code sort the list li in a such way that consecutive terms $t_n,t_{n+1}$ are of the from ...{x_,y_}, {y_,z_}.... i....
2
votes
2answers
68 views

Sorting a list of pairs so that the larger number in the pair appears first [closed]

Imagine I have this data. I want to sort it so that it takes the form: {{<larger>, <smaller>}, {<larger>, <smaller>}, ...}, Any help ...
1
vote
0answers
53 views

How do i sort a list of lists of vector pairs? [closed]

My problem is probably not so difficult but I could not find a solution myself. I am doing computations with 4 dimensional vectors, they represent the vertices of a polytope. So the order of the ...
1
vote
4answers
108 views

Sorting a function

So I have a function f[x : {{_, _} ...}] := f /@ x; f[a_,b_]=:a+b. I can input f[{1,2},{2,0},{3,4}] and get ...
1
vote
1answer
69 views

Sorting the eigensystem of a symbolic matrix

My symbolic matrix $A$ reads \begin{equation*} \left( \begin{array}{ccc} a \left(x^2+y^2+z^2\right) & b y z+i v x & -i v y \\ b y z-i v x & a \left(x^2+y^2+z^2\right) & b x y+i v z \\...
1
vote
1answer
92 views

Nonrepetitive representation of a group of lists (with sharing members)

Background: Lets first construct a square graph (the ha and second points define to implement periodic boundary condition): ...
7
votes
2answers
319 views

List of tuples without duplicates & repeated values [duplicate]

Given some number nand set of values vals, I want to obtain all the tuples/permutations of size ...
0
votes
0answers
43 views

Confusion about the sorting function

The following one-dimensional array can be sorted well: Sort[{Infinity, 10, 2, 1, -4}, #1 < #2 &] But the following two-dimensional array cannot sort the <...
3
votes
3answers
109 views

Ordering a list of rules by its 4 last elements of LHS

I have a list of rules such as ...
1
vote
1answer
74 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
124 views

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

I have a list that looks like this: ...
14
votes
3answers
239 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. ...
8
votes
2answers
507 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
27 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
61 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
114 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 ...
4
votes
1answer
122 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
40 views

How to sort a distance matrix in mathematica

I have the following code which results in the heatmap shown: ...
2
votes
1answer
84 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
132 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
66 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
51 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
30 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
54 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
2 3 4 5
7