Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
3
votes
1answer
56 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
224 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
89 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
86 views

Sorting polynomials based on their y value and finding their intersection

I've got the following list of polynomials, ...
5
votes
2answers
97 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
40 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
142 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
53 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
52 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
80 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
399 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
72 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
478 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: ...
12
votes
2answers
327 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
516 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
44 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
54 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
175 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
142 views

Function for SortBy

Let's say I have the following list ...
3
votes
1answer
123 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
231 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
72 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
479 views

Sorting a list while keeping its correspondence to another list

I have the following two lists: ...
2
votes
2answers
208 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
306 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
212 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
215 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
40 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
803 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
46 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
96 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
56 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
129 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
68 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
82 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
192 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
46 views

Bin arbitrary data using canonical ordering

I have two lists of words, nouns and verbs: ...
5
votes
1answer
104 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
15 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
68 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
83 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 ...
6
votes
6answers
345 views

Simple method to sort versions

The goal is to sort long lists of versions. For example: Input ...
0
votes
1answer
48 views

Delete duplicates and sort a list of sets separately? [closed]

I have a set where it has three subsets. I want to have each element of each subsets appears only once, sorted, but the order of subsets does not change. For example: I want to get from $$ \{\{5,2,2,3\...
0
votes
0answers
43 views

SortBy not working in a delayed output

I have a table of large number of elements, each with three elements, say A = {{a, b, c}, {e, f, g}...}. I am using the function ...
0
votes
2answers
53 views

Sorting a table wrt to last two elements

I have a table-1 having 36 elements, each having the form {A, m, n}, where m & n are the indices (1-6). There is another table-2 having 36 elements {m, n} in a particular order (like {{4, 3}, {2, ...
0
votes
0answers
40 views

How can I get a specific ordering in the matrix and the results of a system linear equations?

I have a linear system of 22 equations and variables. When I create the matrix form it sorts the coefficients on the first row (X1, X10, X11, ...) This ordering repeats for all columns and all the ...
8
votes
1answer
159 views

How to find the position in original list ranked first by SortBy

SortBy is a wonder and convenient way to sort a list using a list of functions with which ties can be broken. ...
3
votes
2answers
63 views

Changing the display ordering of orderless functions?

If I write x = -(1 - 2 G M/r) \[DoubleStruckD]t^2 + (1 - 2 G M/r)^-1 \[DoubleStruckD]r^2 + r^2 \[DoubleStruckD]θ^2 + r^2 Sin[θ]^2 \[DoubleStruckD]ϕ^2; x I see ...
1
vote
1answer
79 views

Feyncalc remove higher-order TensorFunction terms from expression

I am looking for a way to reduce the following expression: ...