Skip to main content

Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
4 votes
4 answers
201 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 ...
SPJ's user avatar
  • 159
1 vote
0 answers
28 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 ...
Kvothe's user avatar
  • 4,491
0 votes
2 answers
120 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 ...
David's user avatar
  • 101
2 votes
1 answer
73 views

How to write a^2 - a b + b^2 - a c - b c + c^2 has the form a^2 + b^2 + c^2 - a b - b c - c a?

I tried ...
vector's user avatar
  • 201
2 votes
1 answer
107 views

Fastest splitter?

Consider some dataset ...
John Taylor's user avatar
  • 5,827
8 votes
5 answers
295 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 ...
sam wolfe's user avatar
  • 4,863
11 votes
6 answers
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 ...
eldo's user avatar
  • 74.7k
4 votes
3 answers
662 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 ...
csn899's user avatar
  • 4,315
1 vote
0 answers
42 views

Identification of terms

I have the following sum on terms: ...
Ruth Murphy's user avatar
3 votes
5 answers
143 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 : ...
Jocelyn Minini's user avatar
5 votes
3 answers
197 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: ...
codebpr's user avatar
  • 2,253
3 votes
2 answers
146 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 ...
metroidman's user avatar
2 votes
2 answers
77 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
6 votes
5 answers
846 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
  • 69.1k
3 votes
1 answer
98 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
0 votes
1 answer
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 ...
y9QQ's user avatar
  • 11
2 votes
3 answers
198 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
  • 809
3 votes
2 answers
219 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
192 views

Sort sequences by their "randomness"

Example matrix (rows always have equal lengths) ...
eldo's user avatar
  • 74.7k
4 votes
1 answer
118 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
  • 18.9k
8 votes
4 answers
333 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
  • 18.9k
5 votes
6 answers
333 views

Restrict sorting to a certain range

Example data (revised to include negative values - see comment of @ydd) ...
eldo's user avatar
  • 74.7k
4 votes
4 answers
254 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}$ ...
am567's user avatar
  • 501
6 votes
2 answers
272 views

Sorting with Missing values

I have the following data: ...
eldo's user avatar
  • 74.7k
6 votes
7 answers
610 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
218 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
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, ...
Keyspire's user avatar
  • 359
-1 votes
1 answer
81 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
73 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
30 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,798
1 vote
1 answer
47 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
311 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
  • 359
1 vote
1 answer
107 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
213 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,111
6 votes
2 answers
261 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.6k
3 votes
2 answers
127 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
122 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
  • 711
6 votes
3 answers
322 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
81 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,295
2 votes
1 answer
92 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
  • 998
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
82 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.6k
5 votes
1 answer
151 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
320 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
56 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
326 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,467
1 vote
0 answers
39 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,467
3 votes
3 answers
249 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.6k
0 votes
1 answer
89 views

Sorting a dataset on multiple column

Following an answer provided by kglr in a previous post: ...
Stuart Poss's user avatar
  • 1,883
1 vote
2 answers
121 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
2 3 4 5
9