# Questions tagged [sorting]

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

437 questions
Filter by
Sorted by
Tagged with
32 views

### Ordering does not function correctly when used as part of another function [closed]

I have 4 functions that take 3 variables as input, namely: ...
1 vote
103 views

### How to sort the terms in a polynomial according to their degree?

I have the polynomial ...
• 251
206 views

### How to tally a list of lists only by considering the first element of the sub list

We need to Tally a list of lists only by considering the first element of the sub lists and then sort the resulting list. As a simple example consider ...
• 159
1 vote
30 views

### Can we find (and understand) the ordering functions used in the various output forms?

Can we use (and perhaps even understand) the sorting functions used in the various output forms (such as OutputForm, TraditionalForm, TeXForm, etc...). This is motivated by the fact that I would like ...
• 4,591
125 views

### How to find curved line in image? [closed]

What's the best way to find smooth curves in an image? I can use EdgeDetect[] to generate a binary image with what looks to my human eye like two distinct smooth curves, and I can get the coordinates ...
• 101
75 views

I tried ...
• 243
110 views

### Fastest splitter?

Consider some dataset ...
• 5,895
297 views

### Ordering with repeats

A quick question on list ordering, how can I easily get the ordering of the list, so that, for {0, Sqrt[3], 2 Sqrt[3], Sqrt[3], 3, 2 Sqrt[3]} I get ...
• 4,913
1k views

### A complicated sorting problem

ClearAll["Global`*"]; list = {{c, c, c}, {b, b, b}, {a, a}, {x, x}, {d}, {e}}; I want to sort the sublists with more than one element in descending ...
• 82.2k
664 views

### How to sort the poker card?

Define the order of sorting as 2>A>K>Q>J>10>9>8>7>6>5>4>3. How can I reorder each of the three sets of data in the list from smallest to largest according to this ...
• 4,587
1 vote
43 views

### Identification of terms

I have the following sum on terms: ...
• 405
146 views

### Sorting logic and generation of letter sequence

In the context of experimental designs, it is common to generate the various treatment names to build the factorial design table. The table of the 2^2 design reads : For the 2^3, the table reads : ...
198 views

### How can I make the list of largest abscissae from a nested list of coordinates?

Suppose I have a nested list of coordinates as: ...
• 2,445
149 views

### What are #1 and #2 in the Sort[{{a, 2, 5}, {c, 1, 4}, {d, 3, 2}}, #1[[3]] < #2[[3]] &]? [closed]

Sort[{{a, 2, 5}, {c, 1, 4}, {d, 3, 2}}, #1[[3]] < #2[[3]] &] In the above code, the list is ordered based on the third element of each sublist. But what ...
• 941
77 views

### Implementing HeapSort in WL

Good day, I am trying to implement the HeapSort Algorithm using WL. My attempt is shown below. ...
922 views

### How to sort filenames in actual numerical order?

I have inherited a collection of files that are numbered... something like: file-0, file-1, file-2, ... file-9, file-10, file-11, ... file-19, file-20, ... When I Import them, they come in scrambled ...
• 69.5k
100 views

### Range of values which not satisfy an equation?

Let $$x+5=z\tag1$$ 1. How can i obtain all the values of $0<x<10$ which don't satisfy the given relation. Edit: of course $x$ and $z$ are positive integers. 2. What command should i use to find ...
• 33
93 views

### Writing a function that sorts by low powers while ignoring higher powers of various variables

I'm writing a Mathematica code with the aim of automating operator mixing calculations in QCD (at least at one-loop order). So far, it can generate Feynman rules and all graphs, assign the rules, call ...
• 11
201 views

### Sorting a list of lines such that they are successively connected

I have a list of line segments of the form $\{u_1,u_2,\cdots,u_n\}$, where $u_{k}$ is of the form $\{\{a_k,b_k\},\{c_k,d_k\}\}$. I want to sort them as $\{v_1,v_2,\cdots,v_n\}$ in such a way that Last[...
• 809
220 views

### How to sort a list of colours and assign it to four categories?

I have a list of colours with RGB values like this : ...
• 105
196 views

### Sort sequences by their "randomness"

Example matrix (rows always have equal lengths) ...
• 82.2k
120 views

### Sorting by SortBy without converting to numerical values

First output returned by Sort is correct - ordered from smaller to bigger numbers. Second output returned by SortBy is correct ...
• 20.2k
336 views

### Double sorting by two criterions using Sort

I was sorting a list of pairs of numbers firstly by second number then by first number. I wanted to use Sort since we can use #1 ...
• 20.2k
341 views

### Restrict sorting to a certain range

Example data (revised to include negative values - see comment of @ydd) ...
• 82.2k
261 views

### How to confirm two sets contain the same vectors in any order?

Say if I have two sets of vectors, for example: $$v_{1}=((0,0,0),(0,1,0),(0,0,1),(1,1,1))$$ $$v_{2}=((0,1,0),(1,1,1),(0,0,0),(0,0,1))$$ I want to find a way of verifying that both $v_{1}$ and $v_{2}$ ...
• 629
274 views

### Sorting with Missing values

I have the following data: ...
• 82.2k
611 views

### Dropping disordered numbers in a list

I have a list of numbers like l1 = (1,2,3,4,8) and clearly, l1 is in order (next number is greater than previous number). Well, ...
222 views

### Build a region from an unsorted set of points (Imported from a .DXF file)

Please consider trying to download the following .dxf files : DXF File - HEA DXF File - UNP DXF File - RRW Context : Every file contains a drawing of a particular type of steel profile used in civil ...
48 views

### What is happening behind an evaluation of Sort with meaningless order-function?

If we try Sort[] with meaningless order-function like Sort[{3, 2, 1}, True] or, ...
• 359
84 views

### Finding the dimensions of the cylinder that can cover $n$ given smaller cylinders (based on empty space, not least materials)

Let $r_k$ and $h_k$ be, respectively, the radius and the height of the $k^\text{th}$ cylinder. We have $n$ cylinders. Let $R$ and $H$ be, respectively, the radius and the height of the big that can ...
75 views

### How to sort this two elements of a list?

Hi So I have the following list: data = {{3.73324*10^10 + 147881. s + 1. s^2, 1}, {3.73324*10^10 + 357017. s + 1. s^2, 1}} (this is a short example, in this case ...
1 vote
32 views

### How to sort a list of n-tuples by a given column, or by the norm? [closed]

I would like to sort a list of lists by the third column (third element in each row), or by the norm of each row, but Mathematica 13.1 ignores my syntax, i.e. returns the same unordered answer ...
• 1,900
1 vote
51 views

### Collect with rational powers

I need a function, which will collect terms next to the same rational power of a given variable. For the input RCollect[3xy^(3/2)+2/y+zx/y-y/x+2*x^z y^(3/2),y] the ...
1 vote
313 views

### Sorting 300K .h5 files

I have 300K .h5 files. I want to list them and plot the data with respect to a parameter. They must be sorted by name otherwise, the plot will be wrong because of time dependency. The name of the ...
• 369
1 vote
112 views

### Sorting by power

I want to sort this table by column "d" such that Mathematica should also take the exponential values into account. Can somebody help me here?
• 73
217 views

### Sorting a List Based on a Given Order

Suppose I have the following input: input={{1, 2, 3}, {-2, 4, 6}, {-1, 3, 6}} How can I sort it according to this list: ...
• 2,111
271 views

### Sorting a list by a single particular element in a specified order

I have a list of lists -- a list of sublists -- that I wish to sort in a specified order. The following function, sortBy2ndElement, sorts a list of lists (...
• 10.2k
133 views

### Order elements of list according to predefined ordering [closed]

I have quite a lot of sublists of different length whose elements I would like to order according to a specific predefined ordering. To be explicit: I am given a specific ordering of indices (i,j,k,l,...
1 vote
125 views

### Is it possible to prevent two functions from commuting?

I have an expression of the following type: x f[a] g[b] where x is a number but f[a] and <...
• 711
340 views

### Sort the nested list by the sublist content; sublists of different lengths

I would like to write the function NewSort function that sorts a list of sorted sublists, basing first on the canonical ordering of subsequent sublist elements. In ...
83 views

### Basic question Sort criteria

Can you explain the following codes? (output of codes) I know that there is the default ordering for any expression in Mathematica and Sort uses the default ...
• 4,325
94 views

### Cycle symmetric Sort for arguments of a function. Put trace in canonical order

I need a new Sort for the arguments of TR that maintains cyclicity, TR[a,b,c] = TR[b,c,a] = TR[c,a,b] cyclicSort[TR[b,a,c]] TR[a,c,b] ...
• 1,030
231 views

### Ordering Arguments of Antisymmetric Functions in Cyclic Way

I have two functions ang and sqa, each of which take two arguments which must be distinct integers between 1 and 6. For instance I could have ang[2,1] or ...
• 137
83 views

### Sort a list using a scoring list with Switch [duplicate]

I have a minimal working example (MWE) list called listToSort that is a list of string triplets: ...
• 10.2k
156 views

### Fail to understand Ordering[], need to get the ranking of elements in a list

Ordering[{2, 1, 6, 4, 7, 10}] gives me as a result, {2, 1, 4, 3, 5, 6}, which I understand, 10 is the 6th smallest element. However ...
326 views

### SortBy with a 2nd argument that specifies not to sort the list?

One can specify the second argument of SortBy not to sub-sort ties, i.e. cases that have identical values according to the main sorting function. ...
• 47.1k
57 views

### Sorting a list by increasing order algorythm [closed]

Im new to loops on mathematica,was wondering how could I create a function to loop through a list which finds the index of the smallest value of that list, makes a sublist from index 1 to that ...
328 views

### How to Partition List into sublists so that it orders down columns when placed into a Grid instead of across rows

Partitioning a List into sub-lists and placing them directly into a Grid orders sub-lists across rows. Is there an idiot-proof built-in function or a simple ...
• 2,467
1 vote
40 views

### How to create a Sort function that does not differentiate between String rule keys and Symbol rule keys

Im trying to Sort Rule-s according to Key-s (or names) but the normal ...
• 2,467