We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
5
votes
1answer
63 views

Why do these commands give different answers?

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

Canonical ordering of days of week

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

Sort Associations by its Values (which are nested lists)

I have associations where the values are nested lists: ...
5
votes
2answers
469 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
113 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
75 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
239 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
115 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
239 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
153 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
90 views

Sorting polynomials based on their y value and finding their intersection

I've got the following list of polynomials, ...
5
votes
2answers
166 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
151 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
74 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
56 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
84 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 ...
12
votes
1answer
423 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
94 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
484 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
360 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
526 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
47 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
183 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
147 views

Function for SortBy

Let's say I have the following list ...
3
votes
1answer
129 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
236 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
76 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
515 views

Sorting a list while keeping its correspondence to another list

I have the following two lists: ...
2
votes
2answers
275 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
313 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
215 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
222 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
42 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
814 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
50 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
141 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
57 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
135 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
94 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
100 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
210 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
49 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
5
votes
1answer
141 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
16 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
76 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
87 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 ...