# Questions tagged [sorting]

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

22 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
118 views

### What do the InternalCompare* functions do?

As part of looking at this question I dug into Names["Internal*Compare*"] and ended up with: ...
119 views

### Dataset row position changed by GroupBy in 11.0.1

Bug introduced in 11.0.0 and persisting through 11.0.1 or later In 10.4.1 and previous versions then using GroupBy in a Dataset ...
111 views

### How do I reassign the ordering of symbols in a polynomial expression?

I have a big polynomial expression, like this: ...
50 views

### SortBy without final cannonical ordering

How can I SortBy a list without final cannonical ordering? E.g. SortBy[{9, 1, 2, 5, 3, 7}, # Boole[# >= 6] & ] returns <...
108 views

### dynamic binary search

Suppose I have a time series of values $v_1, \dotsc, v_n, \dots,$ (think of the data as being generated by repeated function calls, like a Python generator, or being captured in real time) and I want ...
52 views

### Why doesn't Sort work in this case ? (Only numerical values)

Context I want to interpolate a complicated symmetric function f of 2 variables x and y defined by some numerical integral involving Bessel functions. Since computing the integral itself is a bit ...
135 views

### how to sort an expression with descending coefficients?

I have an expression for example psi = 0.24 FF1 FF2 FF3[-1] + 0.23 FF1 FF2 FF3 + 0.5 FF1 FF2 FF3 + 0.25 FF1 FF2 FF3 I wonder how ...
71 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 ...
84 views

### Finding correct combination of functions

I am trying to write code where I have an array $S$ or numbers in any order [5,4,2,1,....] Then I have a specific set of functions that I can write. ...
297 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 ...
101 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 ...
17 views

### How to reverse or restore the order of my cells in Wolfram Mathematica Cloud?

I was completing my assignment and I have no idea what I clicked but all the cells got reversed that is the 1st one on the last and the last is the first cell in my file. I want to restore it back. I ...
44 views

### Confusion about the sorting function

The following one-dimensional array can be sorted well: Sort[{Infinity, 10, 2, 1, -4}, #1 < #2 &] But the following two-dimensional array cannot sort the <...
61 views

### Resorting nested list A according to nested list B

How can sort nested list according to each other? e.g. I have the following list: ...
47 views

### How to sort a distance matrix in mathematica

I have the following code which results in the heatmap shown: ...
30 views

### Preventing mathematica from evaluating "Sort" function, except in the case of numerical values

Say I want to sort the eigenvalues E1, E2, and E3 using "Greater" as following: {EA, EB} = Sort[{Chop[E1], Chop[E2], Chop[E3]}, Greater][[{1, 2}]]; But I want ...
54 views

### "Greater" function gives me wrong order

When I try to sort the eigenvalues of the matrix (Rho) the results seems to be in the wrong order What is wrong with my code? ...
55 views

### Using SortBy on a list of a list of a list

I have quite a typical physics problem at hand, I want the eigenvalues and -vectors of a Hamiltonian matrix. I have a parameter s, which I vary in 1000 steps and for each step I want my H matrix to be ...
55 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 ...
74 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 ...