The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Questions tagged [sorting]

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

263 questions
Filter by
Sorted by
Tagged with
71 views

### Reverse order in evaluated list

I solve the following set of ODE and plot solution of S1 vs k2 (Figure 1). ...
11k views

### How to sort colors properly?

I can't seem to be able to sort colors by their hue and perceptual brightness correctly. Here's my current solution, but it's not right; there are all these dark bands: ...
146 views

### Challenging matrix sorting request?

I have an application in mind, and I need to do the following analysis, but am having a high degree of difficulty conceptualizing it in terms of syntax. I understand what I want, but cannot seem to ...
111 views

### How to canonically reorganize a list using only a limited set of manipulations?

I want to canonically reorganize (like Sort) a sequence of four objects seq[a,b,c,d], but the only manipulations allowed are <...
187 views

### Arrangement Order and Multiple Columns Sorting Order of Associations with Missing Keys

I have the following well-formed JSON string ...
954 views

### Lexicographic ordering of lists-of-lists?

I was surprised to discover that Mathematica does not sort lists-of-lists (LLs) lexicographically by default. For example, applying Sort to ...
155 views

### SameQ for unsorted lists

I have to compare two or more lists and check if they are the same, but their elements can be in different position. For instance ...
141 views

### Descending order of Permutations using Select[Tuples[{5, 4, 3, 2, 1}, {3}], OrderedQ]

I was wondering if there is a possible way to still use OrderedQ and get a descending order of permutations: This is Ascending order: ...
61 views

### Sorting orthogonal null space vectors

My program generates orthogonal null space vectors such as this: ...
1k views

### Difference between Sort and SortBy

I was playing with Sort. All examples I have come across so far, i.e Sort[{1, -1, 3, -3, 2, 5}, Abs[#1]<Abs[#2]&] can expressed in a shorter fashion ...
257 views

### Are there any good mass row/column swapping functions for matrices?

I have the following matrix Keeping the 20 row and 20 column fixed (so the 21st rows and columns because I started at 0)...how do I push each row and column back one spot? I need to push the 0th row ...
169 views

### Find list item before first negative value [closed]

If I have a list like this: ...
491 views

### How to sort the list of all possible 3-tuples of elements from list constrained by a condition?

I want to know if there's a way to impose desired condition on Tuple command output. I have generated a list of 3-tuple of elements from {1,2,3,4,5,6,7,8,9,10} ...
309 views

### Sort Unicode characters

Sorting ASCII phrases works fine: Sort[{"albatrob", "abo", "dict", "star", "mangel", "m"}] (*{"abo", "albatrob", "dict", "m", "mangel", "star"}*) But unless I'm ...
379 views

### Is there an inequality operator (Less, Greater) for lists of elements (as opposed to elements)?

Like multi-column sorting. For example, {1,3,5} > {1,2,5} would return True, while ...
263 views

### Collision detection algorithm (discrete) with sweep and prune algorithm for periodic boundary conditions

EDIT: Question Updated with solution approach, but solution much slower than original implementation. Any ideas to speed up implementation? In the discussion on collision detection (see here) I asked ...
1k views

### Finding minimum of a list of pairs

Sometimes I need to find the Min of a list, whose elements are lists (say of two elements, a pair). Given that Min does not have the option to indicate a sorting function like Sort, I elaborated the ...
124 views

### Error with using SortBy in a Map [closed]

I have a data set in the following format: SomeData = {{a, 1, 2}, {b, 2, 3}, {c, 3, 4}, {b, 1, 9}, {c, 1, 10}, {a, 2, 3}, {a, 3, 8}, {b, 3, 4}, {c, 2, 9}}; The ...
74 views

### How do I reassign canonical ordering of special expressions?

1. Default behavior of Sort Note: this peculiarity is described in a comment to a related question at StackOverflow but I think it's worth restating here at mma.sx. It is estabilished in ...
39 views

### Sort giving unexpected output! [duplicate]

I want to perform sorting on a list of strings, If i take for example the list s s = {"test9","test8","test10"}; If I perform ...
184 views

### Importing, sorting and exporting lists

I have several TSV lists (.txt) of something like 2000*2000 numerics (e.g. 1.8645) to import ...
255 views

### ordered tree data structure

I have a map $f:X\to \mathbb{N}$ and I wish to find $x,x'\in X$ such that $f(x)=f(x')$. Since such elements are rare, I will have to check very many elements and perform many comparisons, so I suspect ...
82 views

### Breaking term order ties [duplicate]

I am interested in creating a table with positive Gaussian integers listed in order based on their norms, with ties broken by lex order. So far I have ...
787 views

### Sorting a list of variables by the numerical value they represent

What would be the simplest method of sorting a list of variables according to the value they represent: Let: ...
447 views

### Max element of a list with a custom ordering function

I need a function to find max element of a list according to some custom ordering function, assuming that the function implements a total order (elements being compared might not even be numbers). ...
639 views

### Multicolumn sorting with ordering functions and precedence

I am aware that the question of "how do I sort on a column" has been asked in various forms, most notably this one. While some powerful solutions have been presented, as far as I can find no one ...
220 views

### How to get the ranked order

data = {33, 6, 10}; Ordering[data] (* {2, 3, 1} *) What I really want is, 3 for 33, as it is the 3rd, if sorted; 1 for 6, as it is the 1st, if sorted; and 2 for ...
188 views

### Comparing two lists lexically

I have two lists of integers a and b of equal length, and I would like to define a>b as ...
300 views

### Disabling Mathematica's automatic sort of output

I used Mathematica to greatly simplify an algebraic expression. I now want to copy it into some notes, but it by defaults things in a very non-intuitive manner. I have a sorting function that will ...
133 views

### A problem about sorting final result

Three days ago, I asked a question about B-Spline Basis fuction here @Michael E2 given a solution to make the order of interval looks normal The easiest way would be to sort it afterwards: MapAt[...
434 views

### SortBy misbehaving?

It maybe a stupid thing in the end but I'm stuck a couple of hours now. I have a list of 2 points on the plane and I want to get the one with the biggest second coordinate. I thought I knew how ...
539 views

### Sorting Lists of lists of arbitrary length

I'm trying to sort a list of lists. The sublists are defined in length, but the length of the list containing it varies. A simplified set might be: ...
1k views

### Collision detection algorithm (discrete) with sweep and prune algorithm

For a more complex collision detection approach, I need an efficient (aka fast) algorithm to prune the elements by using boundary boxes. A classical algorithm is the so called sweep and prune (SAP) ...
300 views

### Sorting out atom types in an XYZ file

I am trying to rewrite the output of "VertexCoordinates" such that instead of a hybrid list of atoms and coordinates that result from using the following input program, I want all coordinates of the ...
441 views

### Complement[] changes order of elements?

Consider this example: Complement[{a, y, c, d, e}, {a, c}, {d}] (*{e, y}*) However, I was expecting the result to be: ...
2k views

### Ordering the Boundary points of a Polygon

I feel like this should be simple, but I keep running into walls. Say someone gives you the coordinates of the vertices of a pentagon and the center point of the hexagon. Is there any way to get an "...
589 views

### How to sort my list?

For example I have two lists of such structure L1 = {{"Australia",a1}, {"USA",a2}, {"Norway",a3},...} L2 = {{"Russia",b1}, {"Norway",b2}, {"Japan",b3},...} I ...
589 views

### Unexpected behavior when using SortBy as a dataset filter

I am still experimenting with datasets. Recently I tried to query the Titanic example to get info on the oldest passengers. Here is what I tried ...
435 views

### Order imported files by their alteration date

Probably a very easy question, but I could not find the answer, so it would be very nice if you can help me: Let us say I have 10 files, all with the extension .dat...
98 views

### Place symbols from small to big

I am wondering how to compare the different values of ω I derived in this code, and place them in order as follows. (use Print ...
74 views

### Sorting a matrix except its last row

Given M = {{"Utah", 2}, {"Iowa", 1}, {"Maine", 3}, {"Total", 6}} I want to obtain the reverse-sorted result like this: ...
125 views

### Sort lists of vertices {indegrees, outdegrees} by indegree

in = VertexInDegree[F]; out = VertexOutDegree[F]; I want both in and out to be ordered by in. Example: graph has nodes a,b,c with indegrees 1,2,0 and outdegrees 0,...
713 views

### How to sort the adjecency matrix of bipartite graph so to have two off-diagonal blocks

In a bipartite graphs there are two class of nodes, say A and B. Each node of class A may interact only with nodes of the class B, and viceversa. The corresponding adjecency matrix is thus composed by ...
722 views

### Import multiple files from folder in order of date added

I have a folder that contains certain files I want to import. In my case those are .png files. As all the files I want to import contain the phrase "accum" in their filenames, I can use ...
156 views

### How do I use Subgraph to sample the $n$ vertices of a graph with the greatest connectivity?

Let $G$ be an arbitrary graph with some number of vertices $||V||$ and some number of edges $||E||$. We can use Subgraph to generate, well, a subgraph of ...
106 views

### Sorting a table of vectors with weights [duplicate]

I'm trying to simplify a table, for instance {{1, {4, 2, 0}}, {4, {2, 4, 0}}, {-2, {3, 3, 0}}, {1, {3, 0, 3}}, {-3, {0, 4, 2}}} Here the first column is the "...
604 views

### Sorting a large file

I have some huge logs, which are text files, containing up to a million rows each, and I need them sorted. Because trying to import one obviously makes Mathematica run out of memory, we must rule out ...
130 views

### Sorting non-numerical lists [duplicate]

The Sort function will by default sort from lowest to highest. In[1]:= Sort[{3, 1, 4}] Out[1]= {1, 3, 4} However, if the list ...