Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
4
votes
2answers
328 views
Why don't * and ^ work as I expected on matrices?
For example, this input...
{{1, 2}, {3, 4}}*{{1, 2}, {3, 4}}
produces this output...
{{1, 4}, {9, 16}}
and this input...
...
4
votes
6answers
185 views
Sorting Matrix elements
I have matrix in as shown, consisting of real numbers and 0. How can I sort it to become out as shown?
...
4
votes
3answers
321 views
Transform a Sum into a List
I want to turn a sum like this
sum =a-b+c+d
Into a List like this:
sumToList[sum]={a,-b,c,d}
How can I achieve this?
4
votes
2answers
248 views
Why can't NumberQ be used as the head of a pattern?
Consider the following:
list={1/First[{}], 1, 2, 1/First[{}], 3};
DeleteCases[list,_NumberQ]
I wanted to remove all cases, which did not match ...
4
votes
6answers
172 views
Filter list with different list in it
I have a list like:
{{{4, 14}, 1}, {{4, 15}, 1}, {{4, 16}, 1}, {{4, 17}, 1},
{{4, 18}, 1}, {{4, 14}, 3}, {4,15}, {{4, 16}, 2},{4,18}}
Now I want to ...
4
votes
5answers
119 views
Convert a list with three arguments {x0,x1, step} into an equidistant table?
How can I convert a list such as:
a = {1, 2, 0.1}
into sequence so that I can pass them into a function, e.g. I want to be able to do something like this
...
4
votes
2answers
122 views
Extracting data from a table under conditions
I have a very large table with two columns. Let's say the name of first column is E and the name of the second is P. How can I get the E values when P = 0.
4
votes
3answers
279 views
4
votes
5answers
197 views
Removing zero values from ordered pairs
I have some processed data, which are basically a collection of ordered pairs in the form:
{{x1, y1}, {x2, y2}, ..., {xn, yn}}
Ordered pairs which have either a ...
4
votes
4answers
186 views
How to pick out the element in a list of lists which satisfies a particular condition?
I have got a list:
...
4
votes
2answers
275 views
List reversion inspired by Python
In python, if you wish to reverse a list, here is the trick:
range(10)[::-1] => [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
Note: ...
4
votes
3answers
131 views
Comparing Unequal Lists of Surnames to Establish Over or Under-Representation
I've been using Mathematica to explore historical records. I have two long lists (one is 69k, the second 17k) of unequal length. They are like so (FWIW, the first list is the first 40 entries from the ...
4
votes
3answers
921 views
Local max/min of Mathematica data sets
Is there a way in Mathematica to find the local maxima of a set of points?
Suppose you have
...
4
votes
3answers
171 views
position of sequence of elements in list [duplicate]
Possible Duplicate:
Finding a subsequence in a list
Question
The position of {3, 5} is the list
{1, 3, 4, 3, 5, 5, 1}
is 3. How can such a position ...
4
votes
3answers
154 views
Replace very small numbers by zero in the output of a list
I have a long nested list, but many elements are numbers of order 10^-18 or less, eg
...
4
votes
3answers
312 views
Summing along rows or columns of a matrix
I have a list of rows in database such as
{{a,b,c}, {d,e,f},{g,h,i}}
I want to be able to add each row across and each column down (like a spreadsheet).
In other ...
4
votes
3answers
174 views
Extracting Pareto elements from a list
How can I extract the Pareto elements from a list?
For example, for that list:
...
4
votes
2answers
195 views
Access pairs of vectors, rather than the matrices, in partitioned data structure at a levelspec
I have some old code to analyze correlation between 2 time series by looking at windows of different lengths shifting across the time series data. The code:
gets 2 sets of time series data (in ...
4
votes
3answers
215 views
Separating positive and negative numbers into two arrays
$c$ is a vector with real numbers.I want to separate the positive ones and the negative ones into two vectors: $a$ and $b$.
I have the following problem:
When I do:
...
4
votes
2answers
130 views
Partition a set into $k$ non-empty subsets
The Stirling number of the second kind is the number of ways to partition a set of $n$ objects into $k$ non-empty subsets. In Mathematica, this is implemented as ...
4
votes
2answers
190 views
How can I use Max[] in a function that is passed a list not find the max of the list
For most functions in Mathematica, passing them a list will call the function on each element of the list. For example:
...
4
votes
2answers
207 views
Simpler way to repeat an execution with 2D points?
q has the coordinates of quadrilateral. I can get the output below with brute-force but I want to find a simpler solution, perhaps something like f<-q[[1;;2]].
...
4
votes
3answers
236 views
Counting elements skipped using Reap & Sow
I am using the following code to filter data based on the percentage change between points.
...
4
votes
2answers
135 views
4
votes
2answers
641 views
Is it possible to compute trapezoidal rule numerical integration?
Is it possible to compute trapezoidal rule numerical integration? I know that Mathematica has Interpolation, and that a list of points can be interpolated and then ...
4
votes
1answer
270 views
How do I treat elements in a list as variables inside a module?
I want to be able to assign values to a list element inside a module. For example if I have:
...
4
votes
2answers
145 views
How find the first element of a list greater than zero (or another criterion) when there is a symbol in the list?
I need to find the position of the first element of a list that is either greater than zero (or some other criterion) or a symbol.
Something like
...
4
votes
2answers
160 views
How can I get every distinct size-n combination of a list?
Let's say I have a list:
{a, b, c}
I would like to, for say $n=2$ get every distinct pair from that list. That is, the expected result should be, for some ...
4
votes
2answers
136 views
How to efficiently find multimap k-itemset frequency
I am doing this to learn association rules. The data d is in format {id, value}, for example:
...
4
votes
2answers
325 views
Is there a way to output histogram x and y data without using the Histogram chart function?
I have a large list of data (3.2 million real numbers), and I would like to plot a histogram of it. The built-in Histogram function is very nice, but on my ...
4
votes
1answer
114 views
Sorting a list and finding an array of indices that sorts the list
How can I sort a list and also get a list of indices that sort this list?
For example:
primary list is a
a={1,4,6,7,0,2};
sorted list is b
...
4
votes
3answers
167 views
Transform vector with lag
Say I have a vector $Z_n$ with and I want to transform it into another vector using this formula:
$X_t=Z_t+0.7Z_{t-2}$
The problem is that I am not quite sure how to get that $t-2$ lag in there. I ...
4
votes
2answers
93 views
How to only work on sublists with non-zero (or positive) values
i have a large compositional dataset which contains non-zero and zero values. here is a sample:
...
4
votes
3answers
126 views
Operations on elements of ragged lists
Suppose I have a list of lists with different lengths, sorted from longest to shortest
...
4
votes
1answer
168 views
Splitting a list using SplitBy, by comparing adjacent elements
Suppose that I have the following list called mylist:
mylist = {80.2, 80.3, 80.4, 327.6, 327.7, 327.8};
I would like to split ...
4
votes
1answer
218 views
Using Partition to allow sublists of different lengths
As a minimal example, suppose I have a list of the integers from 1 to 25. Suppose I want to use Partition to partition the list into sublists of length 10 but ...
4
votes
1answer
275 views
How do I find the Euclidean distance between one point and all the points in a list?
I want to find the Euclidean distance between one point (x1) and a list of points (y1), which contains a lot of coordinates
x1 = killer[[2]]
{6.05102, ...
4
votes
4answers
173 views
clean functional way to get first n rows that yield maximum rank
I have a matrix A and want the matrix consisting of the first n rows of A, having the same rank as A, where n is minimal.
More generally, I want the shortest "start piece" of a list, such that some ...
4
votes
1answer
240 views
Deleting parts of a large list
At present I am running an analysis on economic data. Within the data I was able to identify countries which went through recession. I then calculated for example the average decline rate of GDP ...
4
votes
2answers
133 views
How can I eliminate equivalent equations from a list?
I want to find the numbers $a$, $b$, $c$, $d$ of the plane $ax + by +cz +d = 0$ which make the distance from the point $M(1,2,3)$ to the plane equal to 2. I tried
...
4
votes
1answer
148 views
An easier and more efficient way to combine lists?
I currently have a two lists. The first list contains independent variables $x$, and the second list contains dependent variables in the form of $\{\{f[1][x]\},\{f[2][x]\},...,\{f[n][x]\}\}$.
I want ...
4
votes
1answer
169 views
Timing differences between multiple executions of identical code
I have a
list of pairs of numbers and I'd like to change the sign of the second element in each pair i.e. $(a,b)\rightarrow (a,-b)$.
I'm sure there are many ...
4
votes
1answer
128 views
MapThread with several cells as output
Assume I have defined the following function:
FF[{x_, y_}] := {x^2 + y^3, 3.5*x*y}
I would like to apply FF on a list of ...
4
votes
1answer
178 views
Use single ListPlot for multiple sets of data (on separate graphs)
This is the code I have working for a single set of data. Is there a way I can structure this to have multiple sets of data?
...
4
votes
1answer
250 views
Path queries for tree-structured data
Can anyone suggest documentation or tutorials for developing path queries and indices for (XML-like) tree-structured data?
Suppose data is organized hierarchically in key->value pairs, eg:
...
4
votes
1answer
62 views
How do I group a nested list further according to a rule, and average selected elements?
I have a nested list of numbers like { {36, -244}, {37, -225}, {38, -197}, {48, -200}, {49, -181}, {50, -133} } which needs to be further nested into "bins" according to a rule. I would describe the ...
4
votes
1answer
91 views
Integrating a list of functions
For the purpose of this minimal example, let's say we have a list of functions, like this:
f[y_?NumericQ] := {NIntegrate[z*y, {z, 0, 1}], a y}
I want to ...
4
votes
1answer
159 views
Rearranging a matrix
I would like to convert a matrix which has a structure like this:
{{"A", 10, "D", 1},{"B", 3, "A", 2},{"C", 7, "B", 3},{"D", 6, "C", 4}}//MatrixForm//Print;
...
4
votes
1answer
138 views
A Faster way to combine two Lists of different structures into one of a different structure [duplicate]
I have the following two lists (each containing over 500,000 elements). Here is a sample:
...
4
votes
1answer
182 views




