Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
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 ...
3
votes
2answers
120 views
Subscript and Part: What's going on in this example?
Example
I came across the following simple example from A Beginner's Guide to Mathematica, by McMahon and Topa, which I believe was written circa version 5.2. (FWIW, I'm using v9.)
...
1
vote
1answer
107 views
RowReduce Problem
Here are two examples:
RowReduce[{{3, 1, a}, {2, 1, b}}]
evaluates to
{{1, 0, a - b}, {0, 1, -2 a + 3 b}}
but
...
1
vote
3answers
211 views
How to create functions of arbitrary number of variables?
In the following code what would be the simplest way to generalize it to say some $N_f$ number of $z$ instead of just $z_1$ and $z_2$?
...
6
votes
5answers
309 views
remove -1 values from a list
I would like to turn a list which looks like this one:
{{-1, -1, -1}, {-1, 2, 3}, {-1, -1, 2}, {2, 3, 4}}
into one which looks like that one:
...
0
votes
2answers
82 views
Total elements of a list that have a common first element [duplicate]
Possible Duplicate:
List-operations only when restrictions are fulfilled (Part 1)
I have a set of data like:
...
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;
...
3
votes
1answer
188 views
Implementing Position
As an assignment I need to re-implement Position. I've managed to do this except for one small thing, the resulting list is not in the current format. The following ...
2
votes
2answers
139 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 ...
2
votes
3answers
182 views
Combining two lists of different dimensions into a list of all combinations of points?
I have two ranges of values, one from 0 to 20 and the other from 0 to ...
6
votes
3answers
198 views
Filtering elements from a list
Suppose that I have a list
{{{2, 1}, {4, 3}, {2, 4}}, {{2, 1}, {4, 3}, {3, 1}},
{{2, 1}, {2, 4}, {3, 1}}, {{4, 3}, {2, 4}, {1, 2}}}
I want to make a new list ...
2
votes
2answers
96 views
Simple manipulation of imported data
I am importing 2 columns of numeric data from a data file in the way defined in this answer:
...
23
votes
8answers
1k views
Levels: how do they work?
I cannot understand how Mathematica manages levels, and so it's always a painful try-and-fail to use Flatten. Can someone please give me a very clear definition?
...
6
votes
2answers
192 views
Map a function over the columns of an M x N array
I have a $N \times M$ list of lists, or rather, a list of records and I want to map a function over its columns (e.g. find the mean temperature, age, etc.). Map ...
7
votes
4answers
156 views
Button's command is not evaluated in iteration
I wish I didn't feel like a newbie after several months, but...
If I enter the following:
Table[ Button[ "Number: " <> ToString @ i, Print @ i], {i, 1, 5}]
...
3
votes
1answer
104 views
Exporting/Importing a Table of complex numbers
I'm generating a long table of list of the form:
PN={{1,2,1+i},{3.5,2.6,2}...},{...},...
Using:
Export["PN.dat", PN, "Table"]
...
8
votes
3answers
130 views
How can I use the overhang argument to Partition to avoid using PadLeft and PadRight here?
Say I have a list of values v = {v1, v2, v3, ... }. I need to partition these values to perform operations with a sliding window (think ...
2
votes
1answer
113 views
Computing closest set of points to each point in large set — running out of memory (arrays unpacking)
I have a large set of points in 3D and I'm trying to identify all the points that lie within a certain distance of each point. Then using this data store the vector between the pairs of points.
I ...
5
votes
2answers
190 views
3
votes
1answer
135 views
Removing an ordered pair from a list of ordered pairs if the second element in the list is Less than a Value
I have a list of ordered pairs from a piezoelectric sensor sampled at 2kH. The first element is time and the second, amplitude. I'm trying to remove all ordered pairs in the list of ordered pairs when ...
4
votes
1answer
146 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
192 views
speed up iteration with conditionals plus optimize memory usage
Given list1 and list2 whose elements are vectors of a certain (fixed) dimension, I am interested in the behaviour of a scalar ...
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:
...
7
votes
4answers
170 views
Generating all matrices with 1 (possibly) replaced by -1
I have a matrix $M$, whose dimension I am unsure of, which has only $\lbrace0,1\rbrace$ entries. I would like to generate all the possible matrices that result from changing (some subset) of the $1$'s ...
3
votes
3answers
163 views
7
votes
3answers
301 views
Analytically finding critical values in a hysteresis curve made with ListPlot
Let me start with a super basic explanation of what I'm trying to do, and I will follow with a more detailed discussion afterwards.
From data in the form shown below (a ...
9
votes
5answers
176 views
Is there a better way to add a “key” for the list of GatherBy?
In ruby ,
1.upto(10).to_a.group_by{|x| x%3}
gives
{1=>[1, 4, 7, 10], 2=>[2, 5, 8], 0=>[3, 6, 9]}
I would like use ...
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 ...
6
votes
3answers
288 views
Sum over binary digits of integer
This might seem like a simple enough question but Mathematica seems to simplify inadequately here:
How would you sum over the digits of an arbitrary binary number?
I already tried this:
...
0
votes
2answers
69 views
Extract a List of Co-ordinates from a List of Complex Solutions
Let's say I have this list of solutions from a previous computation:
...
1
vote
3answers
246 views
Generating pairs of additive and multiplicative factors for integers
Given an integer $n$, I want two lists:
a) the set of pairs of the divsors $a,b$ into exactly two factors $n=a\cdot b$,
b) the set of pairs $a,b$ of two summands $n=a+b$.
The code I came up ...
14
votes
6answers
847 views
Insert $+$, $-$, $\times$, $/$, $($, $)$ into $123456789$ to make it equal to $100$
Looks like a question for pupils, right?
In fact if the available math symbol is limited to $+$, $-$, $\times$, $/$ then it's easy to solve:
...
1
vote
1answer
118 views
Optimization of correlation calculation
How can I make the following line of code run faster? Is there a way to do this calculation as a matrix vs vector than vector vs vector?
In the code below, f is a ...
3
votes
2answers
406 views
Optimize inner loops
I'm Mathematica newbie so please be gentle :)
I have this, heavily non-optimized part of code, which I would like to speed up. I have put all matrices to be RandomReal, but in my code they take ...
4
votes
1answer
178 views
Performance of a Do-Loop of variable length
If I'm changing a basis depending on a (non quadratic) matrix $\mathbf{M}\in\mathbb Z^{d\times k}$ and some $\mu\in\mathbb N^k$, i.e. i have an array a of the same ...
1
vote
2answers
215 views
2
votes
0answers
194 views
Generating a function which outputs possible chemical reactions
I want to make a list of chemical reactions and I write them down in a $\require{mhchem}\LaTeX$ format. They are of the following form
$$NA_n^i+MB_m^j \rightarrow \hat NA_{\hat n}^{\hat i}+\hat ...
0
votes
1answer
74 views
Assign the result of Solve in a list [duplicate]
Possible Duplicate:
Assign the results from a Solve to variable(s)
I want to assign the results of a Solve command in a list. For example
Solve[-((287 s^3)/50) == 0, s] returns {{s -> 0}, ...
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
125 views
Operations on elements of ragged lists
Suppose I have a list of lists with different lengths, sorted from longest to shortest
...
5
votes
4answers
192 views
Prevent Part[] from trying to extract parts of symbolic expressions
If you have a list, e.g.
{1, 2, 3}
then you can extract the $k$th part using Part (...
2
votes
1answer
123 views
Why is MapIndexed better than mapping over a range?
Background
I'm working on an application in which I need to create and control two sets of locators. I know from reading the Mathematica documentation and certain posts on Mathematica.SE that this ...
0
votes
0answers
103 views
How to apply rules to the elements of a sparse array? [closed]
I have two text files that I am importing, one is a sparse array of format {large row index,column,value1} and the other is {large row index,value2}. The row values are a small subset of a much larger ...
27
votes
4answers
556 views
Filtering beat-to-beat heart rate data
From an experiment, I have a dataset of beat-to-beat heart rate data: a list of the time between each heart beat in [ms].
The data is measured using an infrared optic sensor at the finger tip. The ...
11
votes
3answers
144 views
Why can't I use Sequence to perform a Select like task?
Suppose I wanted to write down a list of $p^2$, for $p$ a prime between $1$ and $20$. I would expect
Table[If[PrimeQ[k], k^2, Sequence[]], {k, 1, 20}]
to work. ...
3
votes
1answer
149 views
Operations on a List of Vectors (Norm)
I have a List containing vectors. The coordinates are random numbers:
r = {RandomReal[{-1, 1}, n], RandomReal[{-1, 1}, n], RandomReal[{-1, 1}, n]};
Now I want to ...
0
votes
2answers
99 views
Matrix conditional operation
Say I have a matrix of:
tmp1 = 5;
tmp2 = 5;
tmp3 = RandomChoice[{0, 1, 2, 3, 4, 5}, {tmp1, tmp2}];
MatrixForm[tmp3]
How to do a conditional operation of elements ...
6
votes
2answers
309 views
Building matrices by attaching vectors (columns) and matrices
Having the need to attach a column to a matrix or to join matrices to make longer rows is an operation that I use very frequently and I find the Join function ideal ...
2
votes
1answer
112 views
How do I create a histogram out of this datastructure: x[i] = value_i?
Here is my SSCCE:
a[1] = 2; a[2] = 3; a[3] = 6; Histogram[a]
This throws and error though. Here are my questions:
What kind of data type is a? Is it an ...
7
votes
3answers
169 views
Filter list based on date
What I would like to do is remove entries from a list of instrument data when it is in maintenance. The maintenance data I have is a series of dates which look like this;
...


