Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
51 views

Delete duplicates and sort a list of sets separately? [closed]

I have a set where it has three subsets. I want to have each element of each subsets appears only once, sorted, but the order of subsets does not change. For example: I want to get from $$ \{\{5,2,2,3\...
0
votes
0answers
45 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 ...
0
votes
2answers
54 views

Sorting a table wrt to last two elements

I have a table-1 having 36 elements, each having the form {A, m, n}, where m & n are the indices (1-6). There is another table-2 having 36 elements {m, n} in a particular order (like {{4, 3}, {2, ...
0
votes
0answers
42 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 ...
8
votes
1answer
159 views

How to find the position in original list ranked first by SortBy

SortBy is a wonder and convenient way to sort a list using a list of functions with which ties can be broken. ...
3
votes
2answers
67 views

Changing the display ordering of orderless functions?

If I write x = -(1 - 2 G M/r) \[DoubleStruckD]t^2 + (1 - 2 G M/r)^-1 \[DoubleStruckD]r^2 + r^2 \[DoubleStruckD]θ^2 + r^2 Sin[θ]^2 \[DoubleStruckD]ϕ^2; x I see ...
1
vote
1answer
80 views

Feyncalc remove higher-order TensorFunction terms from expression

I am looking for a way to reduce the following expression: ...
0
votes
2answers
98 views
5
votes
2answers
179 views

How to replace columns of a matrix with an unsorted ordered list.

I have a matrix that I would like to replace the values of each column with where they are in an ordered list of values from least to greatest. For example, if I have ...
2
votes
2answers
325 views

How to sort ordered pairs by one coordinate with the other serving as tie-breaker [closed]

I have a collection of $N$ ordered pairs, $$\{\{x_{1},y_{1}\},\cdots,\{x_{N},y_{N}\}\}$$ These ordered pairs can have at most one entry in common, i.e., if $x_{i}=x_{j} \left(y_{i}=y_{j}\right)$ ...
2
votes
2answers
54 views

How can I generate a list of function calls in the sort order of values of the calls?

My problem is that I have a defined function, say, foo, and I am using the built in Sort function to order a sequence of calls <...
2
votes
1answer
121 views

How to sort string codes by their alpha and numeric tokens?

I have a large list of codes of the following form: codes = {"Fee.C21HJ.S4", "Fee.TOxC12.S1", "Fee.TOxC9.2 BB", "Fee.ROxC9.4", "Lag.C39"}; I would like to sort ...
2
votes
1answer
671 views

What is “standard” or “canonical” order? [duplicate]

When trying to sort a list of fractions and quadratic numbers I'm trying to work out why sort orders the quadratics after the fractions. It seems to use the function "OrderedQ" and "standard order" or ...
0
votes
1answer
35 views

Sort solutions obtained with the resolution of a system

After the resolution of a system of 4 equations, i obtained these solutions : ...
2
votes
2answers
86 views

Difference between (#1[[2]] < #2[[2]]&) and (#1[[2]] & < #2[[2]] &) [closed]

For example, if I have a list {{a, 2}, {c, 1}, {d, 3}} and I want to sort it w.r.t. the numbers: ...
8
votes
2answers
706 views

How to SortBy Last and in Reverse order?

I am looking at the two functions SortBy and ReverseSort. ...
1
vote
1answer
38 views

Reordering matrix variables with subscripts

I want to calculate a matrix product that preserves the ordering of variables as x then a then ...
0
votes
0answers
59 views

Sort the terms of expression by the given order?

Let's assume I have the following expression : D[K[x,y],{x,1}] + D[J[x,y],{x,2},{y,2}] + D[U[x,y],{x,2},{y,1}]. Can we sort it by the order corresponding to ...
0
votes
0answers
40 views

Evaluating multiple processes and sort the results

I would like to evaluate the code below and sort the two parameters {f2, M}. Say that i runs from 1 to 10 ...
6
votes
2answers
131 views

Creating lists within lists by sorting

I've been working with lists and am stuck on creating lists within a list based on the first element within that list. So for instance, if I have the list: ...
1
vote
1answer
68 views

MaximalBy in case of missing column entries

I have a large dataset, resulting from a JoinAcross operation, which looks similar like this one (only more complicated) ...
3
votes
1answer
198 views

Sort List of Rules in Numeric Order

I have a list of rules, ...
6
votes
2answers
113 views

Sorting elements in a table with respect to another table

I have two tables, each having three rows (R1, R2 & R3). The elements of R2 & R3 are same in two tables but in different orders. The elements in row R1 are different in two tables. I want to ...
0
votes
1answer
100 views

Ordering elements of a list

Let's define some simple functions ...
2
votes
0answers
43 views

Sort Voronoi cells by their generator points [duplicate]

When I create a Voronoi diagram from a set of generator points and then recover the cells through MeshPrimitives, the order of the cells does not match the order of ...
8
votes
0answers
104 views

What do the Internal`Compare* functions do?

As part of looking at this question I dug into Names["Internal`*Compare*"] and ended up with: ...
3
votes
2answers
232 views

Output all steps of Sort [duplicate]

Is there a way you output each partial result of the Sort function? i.e. Sort[{2,3,1}] {2,1,3} {1,2,3}
-1
votes
1answer
90 views

Extract part of list

I have the following list: {{{1, 0, 0}, {0.5, 1}}, {{2, 0, 0}, {0.5, 1}}, {{2, 0, 0}, {1, 1}}} I would like to take the first part if the second part get a ...
4
votes
4answers
542 views

Synchronize lists

I have two 2d lists: ...
4
votes
1answer
142 views

Sorting a list of rules

When we give several definitions for a function f, the DownValues of f are automatically ...
2
votes
1answer
56 views

How can i sort the bins within bin ranges?

i have following bins and binranges: ...
4
votes
2answers
576 views

Is there a way to sort NSolve solution (roots) automatically?

I had to run NSolve to solve a nonpolinomial equation (it has some square roots in it) to get roots of the equation. I've got a solution that looks something like this (see myrootsSolution). The ...
2
votes
2answers
81 views

Cyclically sort lists with some repeated elements? [duplicate]

This is a continuation of this question. In the previous question we got a routine that can take two cyclically equivalent lists and determine their equivalence if all the elements in each list are ...
14
votes
6answers
938 views

Rearrange the list in a specific way

Suppose I have a list like {"e", "c", "a", "d", "b"} and list of rules {1 -> 5, 2 -> 3, 3 -> 1, 4 -> 4, 5 -> 2}. ...
1
vote
1answer
69 views

Random order list of list

I have a dynamic PopupMenu defined as follow: ...
0
votes
3answers
371 views

Sort matrix rows and columns while keeping heading

I would like to sort columns and rows of a matrix in descending order by the sum of each row/column. However, my problem is that I cannot do so because I need to keep the heading of every column/row ...
1
vote
1answer
127 views

Sort using indices [closed]

I already know the sorted positions, so I want to sort based on that. Say, I have list of {1, 3}, I want the sorted position to be ...
1
vote
1answer
54 views

How to import several files at once according to a specific lexicographic order?

I tried with FileNames but it did not give me what im looking for. My files names are ...
2
votes
0answers
85 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 ...
3
votes
1answer
153 views

Sort pairs — first elements by order of appearance, second elements numerically

I have a long table in this form: A = {{a, 1}, {c, 2}, {b, 5}, {c, 1}, {a, 14}, {b, 7}, {b, 10}, {c, 6}, {a, 4}} and I want to order it by the second column, ...
14
votes
1answer
277 views

Dataset is 20X slow when adding column heads

I'm trying to use Dataset to explore some large data. I notice that the performance decrease more than 20X by adding heads to the columns. Here is an example: We ...
3
votes
2answers
121 views

Sort Output List by Search Value

Consider the following input: ClearAll[dice, sides]; dice := 3 sides := 6 CountsBy[Times @@@ Tuples[Range[1, sides], dice], {1, sides^dice}] This gives the ...
0
votes
1answer
96 views

importing and data handing in cycles

I have a folder with many .dat files to analize, say name_1.dat name_2.dat name_3.dat . . . name_n.dat I also have an auxiliary property.dat file, which is a joint table with all the names: ...
15
votes
2answers
397 views

Fastest way to combine pre-sorted lists?

I need to combine two long, already-sorted lists into one sorted list. My effort below takes advantage of the fact that the lists are already sorted; but it's far slower than just using Join and Sort,...
0
votes
1answer
455 views

Reordering of columns and rows in a cosine similarity matrix

I have the following 7-by-7 matrix of cosine similarity measures: ...
15
votes
4answers
539 views

FindCurvePath for lines (rather than points)

I have need of a function to find a good ordering for a series of lines, as FindCurvePath does for points. Sample data: ...
4
votes
2answers
240 views

Sort a set of fractions with respect to numerator or denominator? [closed]

I would like to know how to sort a set of fractions with respect to numerator (or denominator) or both. For example sort $$ 3/5, 13/21, 19/30, 2/3, 5/7, 11/15, 3/4, 11/14, 4/5, 5/6, 7/8, 9/10, 1 $$ ...
1
vote
1answer
111 views

Sort expression by numerical value of coefficient of two variables with indices

Consider this expression ...
5
votes
1answer
169 views

Sorting Japanese strings in iroha order

When sorting a list of Japanese strings rendered in either hiragana or katakana, one convention is to sort them in gojūon order. This is the convention imposed by ...
1
vote
1answer
101 views

Sort does not sort {0, -Pi/2} [duplicate]

Why is this list returned unchanged by Sort? Sort[{0,-Pi/2}] {0,-Pi/2} While this list is returned reversed? Sort[{0,-1}] ...