Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
2 votes
2 answers
74 views

Implementing HeapSort in WL

Good day, I am trying to implement the HeapSort Algorithm using WL. My attempt is shown below. ...
LambdaHaskell's user avatar
5 votes
5 answers
642 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 ...
bill s's user avatar
  • 68.3k
3 votes
1 answer
95 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 ...
Mathix's user avatar
  • 33
1 vote
1 answer
90 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 ...
y9QQ's user avatar
  • 21
2 votes
3 answers
192 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[...
bkarpuz's user avatar
  • 799
3 votes
2 answers
216 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 : ...
dinesh's user avatar
  • 105
3 votes
2 answers
189 views

Sort sequences by their "randomness"

Example matrix (rows always have equal lengths) ...
eldo's user avatar
  • 48.9k
4 votes
1 answer
114 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 ...
azerbajdzan's user avatar
  • 9,923
8 votes
4 answers
314 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 ...
azerbajdzan's user avatar
  • 9,923
5 votes
6 answers
326 views

Restrict sorting to a certain range

Example data (revised to include negative values - see comment of @ydd) ...
eldo's user avatar
  • 48.9k
4 votes
4 answers
243 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}$ ...
QC123_367's user avatar
  • 491
5 votes
2 answers
267 views

Sorting with Missing values

I have the following data: ...
eldo's user avatar
  • 48.9k
6 votes
7 answers
603 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, ...
cheese.burger's user avatar
3 votes
4 answers
211 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 ...
Jocelyn Minini's user avatar
3 votes
1 answer
45 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, ...
Keyspire's user avatar
  • 359
-1 votes
1 answer
75 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 ...
Hussain-Alqatari's user avatar
0 votes
1 answer
66 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 ...
Granger Obliviate's user avatar
1 vote
0 answers
28 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 ...
florin's user avatar
  • 1,642
1 vote
1 answer
44 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 ...
wedelfach's user avatar
1 vote
2 answers
309 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 ...
Lohrasb's user avatar
  • 349
1 vote
1 answer
94 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?
Miss's user avatar
  • 73
2 votes
2 answers
201 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: ...
emnha's user avatar
  • 2,411
6 votes
2 answers
227 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 (...
Andrew's user avatar
  • 10.4k
3 votes
2 answers
113 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,...
olse barn's user avatar
1 vote
3 answers
116 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 <...
Pxx's user avatar
  • 691
6 votes
1 answer
262 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 ...
wedelfach's user avatar
3 votes
1 answer
78 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 ...
imida k's user avatar
  • 4,047
2 votes
1 answer
85 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] ...
Albercoc's user avatar
  • 966
7 votes
1 answer
228 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 ...
R.W's user avatar
  • 137
3 votes
3 answers
76 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: ...
Andrew's user avatar
  • 10.4k
5 votes
1 answer
145 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 ...
Michael Fischer's user avatar
8 votes
2 answers
319 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. ...
István Zachar's user avatar
0 votes
1 answer
52 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 ...
SkySystem's user avatar
6 votes
3 answers
320 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 ...
Jules Manson's user avatar
  • 2,407
1 vote
0 answers
36 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 ...
Jules Manson's user avatar
  • 2,407
3 votes
3 answers
227 views

Sorting a list based only on a certain property of the first element of sublists

Suppose I have a list called roster. Each element in roster is a list containing two strings: (i) the species of animal and (ii) ...
Andrew's user avatar
  • 10.4k
0 votes
1 answer
79 views

Sorting a dataset on multiple column

Following an answer provided by kglr in a previous post: ...
Stuart Poss's user avatar
  • 1,774
1 vote
2 answers
110 views

Sorting a symmetric matrix alphanumerically

NOT related to my related question! (Different problem source) This time, I want to sort a symmetric matrix M, and it must stay symmetric (i.e. row and col sort is the same). WLOG the diagonal is 0 (...
Hauke Reddmann's user avatar
1 vote
0 answers
134 views

SortBy the second element in the sublists

Is there a way to sort sublists in a list by the sublists' second element? For example, if the list is: ...
Y. zeng's user avatar
  • 465
3 votes
2 answers
435 views

How can I sort {S1, S15, S19, S2, ...}?

How can I sort this in order from small to large? Simple Sort doesn't work here. ...
hana's user avatar
  • 2,688
4 votes
4 answers
185 views

Creating a cycle with conditions

I would like to arrange a gift exchange between 5 people, Alice, Bob, Carl, Danny, and Ellen, and I would like the gifts to be passed in a randomly created cycle (B->C->A->D->E->B), for ...
Wombles's user avatar
  • 792
4 votes
3 answers
325 views

Insert without extra brackets

I have a List1: {{1, -1.1}, {2, -1}, {3, -0.9}, {4, 0}, {10, -0.4}} and List2: {{2, -0.6}, {3, -0.6}} and I would like insert ...
Mam Mam's user avatar
  • 1,753
0 votes
1 answer
52 views

Sorting a list with certain conditions [closed]

I have this List1: ...
Mam Mam's user avatar
  • 1,753
4 votes
3 answers
354 views

How to replace the element in list of list by its ordering index

I have a list of list: res={{9, 1, 5}, {3, 6, 12}} I want to change it to res={{5, 1, 3}, {2, 4, 6}} by following their ordering ...
mmmm's user avatar
  • 95
10 votes
7 answers
518 views

Collect terms with the same denominator

I have an expression $$\frac{A}{x}+\frac{A_2}{x^2}-\frac{D_2}{x}+\frac{C_2}{x^2}++\frac{F_2}{x^3}+\frac{I_2}{x^2y}+\frac{U_2}{y^2x}+\frac{Z_3}{x^2y}+\frac{J_2}{y^2x}+\cdots$$ and I am looking for a ...
jojo123456's user avatar
3 votes
4 answers
219 views

Finding relative ordering of two lists

Suppose you have two lists A and B which are related by a permutation, and have no repeated elements. Is there a simple and ...
ComptonScattering's user avatar
3 votes
2 answers
93 views

Parting a table by second column elements

I have 2 X m table with elements {{x1, y1}, {x2, y2}, .... {xi, yi}, .....{xm, ym}}. It is an experimental data, which can be seen in the attached picture. There is a significant noise and ...
user49535's user avatar
  • 1,185
6 votes
4 answers
651 views

Find min and max indices of highest and lowest elements in sorted list

I have a list of integers of the form ...
az123p's user avatar
  • 239
2 votes
4 answers
221 views

Counting number of points in fluctuating lines that fall within a circle

I have a list of points pts that fluctuate around some mean line. pts is pre-sorted by the projection of the points onto this ...
az123p's user avatar
  • 239
6 votes
1 answer
166 views

Fastest Way to Find nearest indices between two sorted lists

I have a sorted list of floats of length n and an n x n list of lists, where each nested ...
az123p's user avatar
  • 239

1
2 3 4 5
9