Questions tagged [sorting]

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

263 questions
Filter by
Sorted by
Tagged with
143 views

Canonical ordering of days of week

The entities representing the days of the week sort alphabetically: ...
51 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. ...
71 views

Sort Associations by its Values (which are nested lists)

I have associations where the values are nested lists: ...
463 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. ...
110 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 ...
74 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 ...
228 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 ...
113 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: ...
237 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 ...
131 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 ...
90 views

Sorting polynomials based on their y value and finding their intersection

I've got the following list of polynomials, ...
146 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 ...
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. ...
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 ...
146 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: ...
65 views

how to sort an expression with descending coefficients?

I have an expression for example psi = 0.24 FF1 FF2 FF3[-1] + 0.23 FF1 FF2 FF3 + 0.5 FF1 FF2 FF3 + 0.25 FF1 FF2 FF3 I wonder how ...
54 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 ...
83 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 ...
414 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, ...
89 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. ...
483 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: ...
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 ...
525 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....
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 ...
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 ...
179 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 ...
144 views

Function for SortBy

Let's say I have the following list ...
128 views

Sorting of a list with different lengths

I have a list of disordered numbers. They are collected in different lists. I mean ...
233 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., ...
75 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: ...
503 views

Sorting a list while keeping its correspondence to another list

I have the following two lists: ...
254 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, ...
310 views

What is the Alphabetical Inequality Test?

Mathematica can sort {"b","d","a","c"} into {"a","b","c","d"} with a simple application of ...
214 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 ...
222 views

OrderedQ with string arguments

I don't find these results consistent: OrderedQ[{"a", "A"}] True OrderedQ[{"a2", "A1"}] False Is there any ...
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 + c[1,2,3] + c[1,2],$$ $$g = c + c[2,1],$$ Code: ...
808 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 ...
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 ...
132 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: ...
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): ...
133 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, ...
84 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: ...
93 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 ...
208 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 ...
49 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
137 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, {#[], #[]} &] As you ...
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 ...
75 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 ...