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

learn more… | top users | synonyms (1)

3
votes
2answers
136 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 ...
0
votes
1answer
36 views

Sort a multidimensional list row-wise [closed]

Suppose I have a multidimensional list as shown below: RandomInteger[{1,10},{3,7}] I obtain the results: $$ \left( \begin{array}{ccccccc} 3 & 8 ...
4
votes
3answers
187 views

Counting number of inversions

Is there an inbuilt method to find the number of inversions in a set of numbers? I found Inversions in Combinatorica but when I ...
14
votes
3answers
1k 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 ...
3
votes
1answer
53 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 ...
-1
votes
1answer
48 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 ...
2
votes
1answer
55 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: ...
1
vote
1answer
68 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 ...
1
vote
2answers
93 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 ...
0
votes
1answer
60 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 ...
18
votes
5answers
681 views

How do I reassign canonical ordering of symbols?

I have a big polynomial that evaluates to: $$A^2 e^2 \phi ^- \phi ^++A e \phi ^- \phi ^+ c_{2 w} g_Z+\frac{1}{2} A e g h W^- \phi ^+ +\ll13\gg,$$ which is supposed to represent some terms in the ...
0
votes
1answer
61 views

Sorting lists of lists with string elements [closed]

I have a list of sublists. One element of each sublist is a string element. For example: list = {{1, "banana", 3}, {3, "orange", 1}, {2, "apple", 2}}; When I ...
3
votes
2answers
164 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 ...
0
votes
2answers
49 views

Sorting non-numerical lists [closed]

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 ...
2
votes
2answers
257 views

How to plot several functions without jumping? (multiple eigenvalues of a system as functions of 2 parameters)

I've been working on this research problem for months with some success by no global/proper solution to the problem. So I have square, Hermitian matrices of various sizes ($8,20,38$ dimensions) with ...
2
votes
3answers
244 views

Re-arranging / selecting of a data table very slow in For loop [duplicate]

My task is quite simple; I have a table of data like M = {{1,2}, {1,3}, {3,4}, {5,1}, {6,9}, {6,8}, {6,1}}; so the table is sorted with respect to the first ...
9
votes
2answers
431 views

Rearranging a List

I am trying to rearrange/sort a list i.e. {{1,2},{10,140},{43,10},{1,140},{43,2}} into ...
1
vote
2answers
74 views

Sorting lists with elements that are identical [closed]

How can I sort the following list: list={{1498, 1495}, {1498, 1733}, {1553, 1552}, {1552, 1495}, {1733,1776}, {1776, 1553}}; such that the next group contains ...
0
votes
1answer
65 views

Produce a 1-dimensional list of all unique matrix elements

We have some symbolic matrix m, e.g. m={{1, x, 4 x + y},{0, x y + 4x, 4x},{7 x, x, 4x + x y}} and we want to produce as output a list of all the unique elements ...
2
votes
1answer
191 views

Rank functions of n by their order of growth

I'd like to rank some functions according to their order of growth (e.g. n^2 < n^3). I'm not sure how to do order of growth in mathematica, so I was trying to ...
4
votes
1answer
159 views

Are there functions or packages in Mathematica to sort subsets in lex order, colex, revlex, etc.?

I am looking for non-canonical sorts of lists. A function that would give: Sort[X, "order type"] With "order type" being colex, revlex, etc.
1
vote
2answers
135 views

Sorting lists element by element [duplicate]

I have a problem regarding list sorting. Let's say I have a list of lists obtained using Subsets[], of the form ...
3
votes
1answer
143 views

Sorting an Array with words in different languages

Array consists of words of different languages. I need to sort elements in reverse alphabetical order and make a list of elements, which consist of english letters. Example of array which consist of ...
3
votes
1answer
148 views

Windows Explorer Natural Order

Currently there are a list of notebooks in Windows that I am processing in a folder. Ideally I would like the notebooks to be concated in the same order as how they display in Windows Explorer. I ...
1
vote
2answers
125 views

How to sort Table/Matrix including legend(Labellings)

I want to sort table including its legend for graph I have table similar to M1 M2 M3 1 5 2 3 1 4 4 2 -10 5 7 11 6 -2 1 ...
0
votes
1answer
68 views

Problem with Sort - unexpected order with Sqrt [duplicate]

Sort[{13, Sqrt[157], Sqrt[163]}] (*{13, Sqrt[157], Sqrt[157]}*) Sort[{13, Sqrt[157], Sqrt[157]}, #1 < #2 &] (*{Sqrt[157], Sqrt[157], 13}*) This seems ...
9
votes
5answers
2k 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 ...
4
votes
1answer
341 views

How to implement Kemeny-Young method? (rank aggregation problem)

Prehistory I am trying to make some statistical analysis of some experimental data, arises from measurements made ​​on an ordinal scale. I faced with the problem of rank aggregation: to get from ...
7
votes
1answer
214 views

How to get all possible orderings (equal ranks allowed) for given set of $N$ objects?

Hope there is a solution besides the tedious generation of nested loops. (Trying to avoid reinventing the wheel.) Here is an example with $N = 3$ objects. There are $13$ needed orderings (first ...
1
vote
1answer
56 views

How can I sort the polynomial by the degree of $x$

f1 = a x^2 + b x + c + x^3 (* a x^2+b x+c+x^3 *) f1 /. x -> (x - a/3) // Expand (* (2 ...
5
votes
1answer
185 views

Efficiently searching a list for the position of the closest number to a specified number

Searching by closest and position I wasn't able to find an answer—but found Nearest by guessing. Nearest, however, returns ...
0
votes
1answer
83 views
3
votes
3answers
138 views

Properly ordering the output of FileNames for a directory consisting of files with consecutive integer names [duplicate]

Say I have a number of files in a directory at some location (C:\dir1\dir2\dir3...), and I pull an array of strings corresponding to the file names with the command: ...
11
votes
1answer
262 views

Is there a “precedence table” for the canonical Sort ordering?

This answer in which I wrote about the Operator Precedence Table was unexpectedly popular. That got me thinking about similar things, and I am wondering: Does an "ordering table" exist for the ...
7
votes
2answers
223 views

Complement on pre-sorted lists

Is there any way to instruct Complement to skip the sorting part? If the answer is no (likely), the next question would be: how can I remove from a sorted list ...
4
votes
2answers
241 views

Sorting a matrix alphanumerically

Somewhat related to Sort matrix by columns and rows without changing them, but more general. I'd like to sort a square matrix (a 3 by 3 in my case, but surely the general solution will treat any), ...
8
votes
4answers
315 views

Gather list elements by index

The following list has some elements that are labeled. For example {1, 2} -> 1, {-1, 3} -> 3, etc: ...
14
votes
1answer
200 views

Ordering function with recognition of duplicates

Fairly often I have a need to get the Ordering of an expression but with recognition of duplicates. For example: ...
0
votes
1answer
78 views

Ordering under assumptions

I have a three-element list which contains inverses of a function u, like so: ...
9
votes
2answers
173 views

Why does Sort fail in this simple example?

I'm sure I'll be embarrassed by the answer, but I don't understand why I get the following result: list = {{9, "b"}, {4, "a"}, {7, "k4"}, {6, "k3"}, {5, "w"}} ...
12
votes
6answers
520 views

Sort+Union on a list

Probably this is too trivial question for this forum but for some reason I am not getting it on my Mathematica 7 so far. I have a list ...
0
votes
1answer
100 views

Sorting a list of triplets by first element of each triplet fails

In the last line of code, I´m trying to order the matrix by the first column. I want to store in the Array t2tlistsorted ( 100 x 3 ), but I can´t. ...
3
votes
2answers
100 views
17
votes
3answers
336 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
votes
1answer
98 views

Sorting the element in a PDB text file

I am a new user of Mathematica and currently using version 9. I want to rearrange the element of one PDB text file with respect to another PDB text file. Suppose I have a PDB file like this: ...
0
votes
1answer
132 views

Using Sort vs SortBy

So I have two lists, A and B. I put them into lists = {A,B}I want to sort A such that Im[#1]<Im[#2]& which I can do fine ...
8
votes
1answer
173 views

How to tell when a job is too big for the pattern matcher?

Pattern matching is great but it has its limitations. Consider sorting a list of numbers from smallest to largest: ...
1
vote
1answer
284 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 ...
2
votes
2answers
223 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 ...
5
votes
3answers
379 views

Order list of monomials by degree (Pascal's Triangle)

Suppose I have the following list of monomials: {1,x,x^2,y,y^2,x*y,x^2*y,x*y^2,x^2*y^2} How could I manipulate it to get ...