Questions on the sorting/ordering functions of Mathematica (Sort, SortBy, Ordering, etc.).
18
votes
4answers
599 views
Sort lists according to the order of another
I have three parallel lists (i.e. the elements in position i of each list are related). I want to sort the first list using the function Sort and make the same changes to the other lists so that I ...
12
votes
2answers
794 views
Simple algorithm to find cycles in edge list
I have the edge list of an undirected graph which consists of disjoint "cycles" only. Example:
{{1, 2}, {2, 3}, {3, 4}, {4, 1}, {5, 6}, {6, 7}, {7, 5}}
Each ...
7
votes
5answers
790 views
How to find rows that have maximum value?
Suppose if I have following list
{
{10,b,30},
{100,a,40},
{1000,b,10},
{1000,b,70},
{100,b,20},
{10,b,70}
}
How to find rows that have max value in ...
18
votes
11answers
653 views
Generating an ordered list of pairs of elements from ordered lists
I have a pair of ordered lists. I want to generate a new ordered list (using the same ordering) of length n by applying a binary operator to pairs of elements, one from each list, along with the index ...
15
votes
2answers
368 views
Ordering problem
Let's look at the following example.
Ordering[{0, 20 Sqrt[5], 40 Sqrt[5], 20 Sqrt[5], 20 Sqrt[10]} // N]
gives the right answer
...
13
votes
3answers
715 views
Sort per column
I have some data:
data={{"a", 1, 1}, {"a", 1, 2}, {"a", 1, 3},
{"c", 2, 1}, {"b", 2, 2}, {"b", 2, 3},
{"c", 3, 1}, {"a", 3, 2}, {"a", 3, 3}}
When I ...
7
votes
3answers
164 views
Retaining and reusing a one-to-one mapping from a sort
Imagine I sort the elements of an array $Q$ by some means. Perhaps I sort strictly by the elements in the first column, perhaps I use SortBy[...] to sequentially sort by the elements in successive ...
9
votes
1answer
138 views
How to pass composite function list to SortBy?
In order to sort alphanumeric-as-string data of the form {"T3", "T14", "T1", "E2"}, so that "T14" comes after ...
2
votes
2answers
140 views
Position function not always retuning an answer even with no apparent problems
I'm having some problems with Position.
Sometimes it will give an empty list instead of the actual position of the element I am looking for when that element is ...
17
votes
4answers
376 views
Sort strings by natural ordering
Is there an easy way to sort strings according to their natural ordering?
For example a list of file names
...
17
votes
3answers
241 views
Unexpected result {“.a”, “co”, “.m”} from Sort[{“.m”, “.a”, “co”}]
I came across the following situation:
Evaluating
Sort[{".m", ".a", "co"}]
Results in
{".a", "co", ".m"}
I wondering: ...
1
vote
1answer
117 views
How do I sort complex numbers?
Okay, so I posted something about sorting, and it was linked as a duplicate to This post
However, I am having problems trying to sort a list that contains both real and complex numbers. I put them ...
