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

learn more… | top users | synonyms (2)

0
votes
0answers
4 views

Role of Accuracy in numerical evaluations, SplitBy vs GatherBy

This is a follow-up question to this question. I generated a list by substituting the results of a solve[] routine and set: ...
7
votes
3answers
174 views

Gatherby/Splitby and Sort a list

So let's say I want to group a list of points based on their distance from the origin. I would do something like: ...
1
vote
0answers
23 views

Order of importing data from files

I have many text files numbered from 1 to 1 million in numerical order. Within each text file is 5 columns of data (TAB spaced) with many rows. I effectively want to take the minimum value from each ...
0
votes
1answer
39 views

Can't sort my list numerically for larger numbers than 10 e.g. 1,10,100,2

I want my files names in real numerical order so 1,2,3,10,12. However it is currently putting them in order like so: 1,10,12,2,3 Input: ...
2
votes
1answer
237 views

What is wrong with my user-defined ordering function?

I've defined ordering function: myOrderingFunction[arg1_, arg2_] which always return True or ...
1
vote
1answer
58 views

How to check a clockwise direction for a list of point [closed]

Suppose that we have a list of points and we need to order them in clockwise direction by starting from a special point. I implemented this code to order them but I need to detect if it is ordered in ...
3
votes
1answer
146 views

Sort by returning positions

How can I computationally efficiently sort a list so as to return the positions and not the actual values at those positions (which SortBy does)?
4
votes
3answers
87 views

Change Contour Plot Overlap Ordering

I have a contour plot for which I have selected a finite set of contours. However, the contours overlap in some places and I would like to reverse the order in which they are drawn. In other ...
1
vote
0answers
57 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. ...
0
votes
1answer
52 views

Unexpected result from Sort with symbolic values

I think Sort should be able to sort symbolic values that are reducible to numerical values, but this example seems to get a wrong answer (here is a simplified ...
2
votes
2answers
39 views

Select Only Positive Values and Prepend a Title

I have the following list: ...
5
votes
1answer
83 views

How to order a list to match the order of another list?

How can I order a list to match the order of anoter list ? For example: Suppose I have the lists x = {3, 1, 5, 7} and ...
3
votes
1answer
72 views

SortBy behaving strangely with missing data

I'm trying to create a grid that shows the largest data value from a list. What I have mostly works- the problem comes when there is missing data. You can't really tell here, but all of the ...
11
votes
5answers
424 views

How to sort list of mixed types of elements with each type a specified canonical order?

For example, here is a list {{1, "u"}, {6, "d"}, {3, "u"}, {4, "d"}, {2, "u"}, {5, "u"}, {3, "d"}, {1, "d"}, {4, "u"}, {2, "d"}, {5, "d"}, {6, "u"}} The ...
6
votes
2answers
249 views

Wolfram Language symbols by their Ranks

I'd like to get the top 50, the bottom 50 and an ordered list of all Wolfram Language symbols based on their "Ranks". With ...
0
votes
1answer
39 views

Sorting in descending order of list [closed]

I have a list m = {{a, 20}, {b, 10}, {c, 50}, {d, 5}, {e, 100}} and I want to apply Sort on this in descending order on ...
4
votes
2answers
111 views

Sorting and keeping the main format of list numbers [duplicate]

I have a list with these elements: list={1/2 (1 + Sqrt[5]), 1, 1, 1/2 (1 - Sqrt[5]), 0}; I want to sort them with ...
3
votes
2answers
222 views

Exercise using Sort

I have to order the following list according to the sum of the powers of each element of the list, using the function Sort. ...
2
votes
1answer
52 views

Sort a list of derivatives

I have a list of variables, both constant and functions of an independent variable, including derivatives. I'd like to sort these by the variable name, rather than the derivative order. For example, ...
1
vote
1answer
36 views

Reverse order in evaluated list

I solve the following set of ODE and plot solution of S1 vs k2 (Figure 1). ...
14
votes
3answers
2k 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: ...
7
votes
1answer
115 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 ...
4
votes
1answer
57 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 ...
2
votes
1answer
114 views

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

I have the following well-formed JSON string ...
10
votes
1answer
266 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 ...
6
votes
1answer
95 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 ...
1
vote
1answer
77 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: ...
0
votes
0answers
31 views

I have trouble in sorting a matrix in wolfram mathematica [duplicate]

I have an array of five elements, I have to make permutations of 3 elements. I have my code: A = {1, 2, 3, 4, 5}; n = Permutations[A, {3}]; Now I have to sort ...
0
votes
1answer
33 views

Sorting orthogonal null space vectors

My program generates orthogonal null space vectors such as this: ...
9
votes
4answers
411 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 ...
2
votes
2answers
203 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 ...
2
votes
5answers
108 views

Find list item before first negative value [closed]

If I have a list like this: ...
1
vote
3answers
200 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} ...
3
votes
1answer
56 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 ...
5
votes
2answers
367 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 ...
1
vote
0answers
178 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 ...
2
votes
3answers
237 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 ...
1
vote
1answer
58 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 ...
1
vote
0answers
43 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 ...
0
votes
0answers
25 views

Sort giving unexpted 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 the Sort function i will get: ...
1
vote
1answer
105 views

Importing, sorting and exporting lists

I have several TSV lists (.txt) of something like 2000*2000 numerics (e.g. 1.8645) to import ...
2
votes
1answer
142 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 ...
0
votes
1answer
35 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 ...
6
votes
4answers
567 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: ...
10
votes
1answer
260 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). ...
5
votes
1answer
169 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 ...
2
votes
4answers
96 views

While subpartitioning the elements in list using GatherBy, can I corresponding subpartition the elements of an unrelated list?

If we have a list like the following: list1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; And we use GatherBy to subpartition is according to a test function ...
3
votes
1answer
112 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 ...
2
votes
3answers
111 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 ...
1
vote
1answer
61 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 ...