Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.

learn more… | top users | synonyms (5)

3
votes
1answer
34 views

Difficulty with LevelSpec. Product of empty set should be 1

I have a matrix newm = {{{}, {}, {-p}}, {{d}, {e}, {p}}, {{g}, {h}, {i}}}; MatrixForm[newm}; whose elements are lists. I would like to multiply the elements of ...
0
votes
0answers
20 views

Remove background from multipeak data [duplicate]

Let's say I have a a very large list of data in the format {{n,f[n]}} so something like {{1,600},{2,700},{3,1100}...} and if this data is plotted, then it will look like a sum of Gaussian functions+a ...
5
votes
3answers
227 views

Removing background from peak function

Let's say I have a a very large list of data in the format {{n,f[n]}} so something like {{1,600},{2,700},{3,1100}...} and if this data is plotted, then it will look like a sum of Gaussian functions+a ...
10
votes
4answers
201 views

Timing problem with ReplaceRepeated

I have the following data: ...
6
votes
2answers
370 views

Exception with GatherBy: gathering complex conjugates

I want to gather the complex-conjugates that are in a list, but with an exception: only if the imaginary part isn't zero. For example: ...
11
votes
3answers
359 views

get position index for all element in a list

For example mat={{a,b},{c,a,a}} How to write a function posindex that posindex[mat] will ...
-1
votes
3answers
67 views

Multiply equations in lists

list = {x + 1, x - 3, {x - i, x + i}} The last two elements should be multiplied. Desired output is: {x + 1, x - 3, x^2 + 1} ...
0
votes
1answer
53 views

Multiply elements within a list [closed]

How do I multiply elements within a list? list = {{1}, {2, 3}, {4, 5, 6}, {7}, {8,9}} Desired output: {1, 6, 120, 7, 72}
2
votes
1answer
90 views

How to take every second element [duplicate]

If I have {1,2,3,4,5,6}, how do I take all the second elements into a new list? So I want a list like {2,4,6}.
4
votes
1answer
118 views

Grouping the first two elements in a list of ordered triples

I have a long list of the form ...
3
votes
1answer
122 views

Efficiently generating plots from lists of differing lengths

I guess this is more of an informatic question. A quite complicated function of mine generates me a list of valid points, depending on a parameter, like this: ...
5
votes
2answers
88 views

Overlap between lists of sublists with different dimensions

I have two lists of sublists. The sublists in the first list contain three elements while the points in the second list contain four e.g.: ...
2
votes
1answer
109 views

Collecting Data in table

I wrote a program (with help of the stackexchange) that is supposed to run in a loop. Each time the program runs, it exports a small data. Is it possible to generate a table where each run adds the ...
7
votes
5answers
229 views

Referencing previous elements in the same List

I'm looking for a way to reference an element within a List to get another element in the same parent List. I can't really see ...
1
vote
1answer
130 views

How to find period of a discrete sequence?

For example, {1,2,3,4,5,6,7,8} has period 1, the base is {1} {1,2,4,5,7,8,10,11} has period 3, the base is {1,2} I ...
4
votes
1answer
123 views

Why does my MapThread expression fail in this case?

This morning, I opened one of my previous notebooks and evaluated it. Surprisingly, the code produced an error. This took me a whole four hours to find the problem and it is with ...
7
votes
2answers
153 views

Allocate amount A according to the distribution of amount B

I have a cost that varies by category and date. I also have the counts of each item type within each category and date. I want to distribute the cost to each of the item types. I'm trying to use ...
2
votes
2answers
95 views

How to transform data in character form into a sensible form?

I have a data output from a device in a form of a string. I need to transform it into such a form that I can work with it, such as plot columns with respect to one another and such. After a apply ...
3
votes
0answers
73 views

Delete many elements of a list at once [closed]

I have a list of points in 2d: myList = {{x1,y1},... , {xn,yn}} And a range of points I want to remove from the list, for instance: ...
1
vote
1answer
35 views

Select on 3D-table along diagonal

I have the following data set on the form (x, y, z) ...
2
votes
1answer
61 views

Table: calculate the intermediate variable but not list them

I want to list {a,c} but c is depend on b, suppose the dependence on ...
14
votes
4answers
400 views

A replacement problem

list = {1, x, 3, x, 4, x, x, 3, 4, 3, x, 2, 3, x, 8, 7}; If there is exactly one integer between two x I want to replace it with y: ...
9
votes
1answer
158 views

How to write this pattern in Pick function

Suppose I have a list called mask composed of 1,2,3,...n. n is different in different situation. Let me takes n=3 for demonstration ...
18
votes
6answers
822 views

Recursively appending elements to a list

In wanting to demonstrate the power of Mathematica, I wanted to show my 11-year-old son how we could validate that his sequences homework was correct. We could generate the next value in sequence in a ...
0
votes
1answer
128 views

How to get all possible combinations of this list? [closed]

I'm trying to get all possible combinations of {0,-1} for a certain length. So let's say I want length 2. Then I want my output to be ...
4
votes
2answers
109 views

Ordering and summing elements of a list based on their indexes

Suppose I have a vector. I assign to every vector index a four-element array, in such a way that index i corresponds to ...
5
votes
0answers
57 views

SimilarityRules for SequenceAlignment of two lists

I am trying to use the SimilarityRules option of SequenceAlignment to customize its output. This works perfectly for strings, ...
2
votes
1answer
45 views

ndsolve interpolatingfunctions not shown/evaluated

Using this technique from Simon, I want to solve a matrix differential equation with a matrix that contains an explicit time-dependence(our variable), but I want to be able to solve this problem for a ...
5
votes
1answer
86 views

ListConvolve with Padding -> Fixed?

The built-in function ImageConvolve takes a Padding option that "specifies what padding to use when extending beyond the ...
6
votes
3answers
205 views

Creating new lists

We have the following list data = {{1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,-1,14}} If I want to create a new list containing the first and the fourth elements of ...
3
votes
1answer
84 views

How to insert into a nested list/association?

Considering following nested structure: ...
2
votes
1answer
48 views

Create array of “positions”

How do I create an array a of generic depth $n+1$, such that exactly: a[[i1]][[i2]]...[in]] = {i1,i2,...,in} ? In words, such ...
3
votes
1answer
118 views

Way to generate all multisets

I have a set $\left\{\{1,2\}, \{3,4\}, \{5,6\}, \{7,8\}\right\}$ (for example) and want to generate all sets of $n$ elements with repetition but without counting the same multiset twice. So I want my ...
4
votes
1answer
65 views

How can I “permute” an ordered pair over all the permutations of say $S_4$?

I want to make an action table of the symmetric group (say $S_4$) acting on the set of unordered pairs of distinct vertices of a square. I have the list of such pairs: ...
4
votes
3answers
225 views

Cleaner way to find a list item within an array.

So I have a list somewhat like this: ...
7
votes
1answer
168 views

Remove leading and trailing zeros from a list

This functions and gives the desired result: {1, 0, 2, 0, 0} /. {x___, 0 ...} :> {x} {1, 0, 2} But with leading zeros it doesn't: ...
0
votes
1answer
91 views

How to plot two lists in the same graph maintaining the scale of the points?

I need to plot two lists of complex numbers in the same graph to show some results, so I'm using the following lists to do that: ...
7
votes
6answers
381 views

How to select sub-lists having at least one element that matches a pattern

This will probably be a very easy question, yet although I did find a relatively similar one, I couldn't use the answers there to solve my problem (I'm still a novice). I'm simulating 10 blocks of ...
4
votes
0answers
100 views

Bug in ListLinePlot[] when Filling up and down?

I'm trying to understand this apparently incorrect Filling behavior in ListLinePlot[]. Evaluating this ...
3
votes
5answers
236 views

Loop over list of lists

Greetengs,im totally new here. I cant fined answer at other simular questions, so i create a new one. I have optical spectra in the following format: ...
3
votes
1answer
121 views

Using Select with Alternatives

I want to select the elements of a list like: ...
3
votes
2answers
116 views

Swap LHS's (or equivalently RHS's) of two rules in a list

Assume I have a list of rules, each of the form $a_i \rightarrow b_i$. What is the best way, for some $i$ and $j$, to swap $a_i$ with $a_j$ (or equivalently, $b_i$ with $b_j$). Currently, I have ...
14
votes
4answers
289 views

Fast Selections Testing on Inequality

Is there a functional idiom for fast selections testing on inequality? For example, finding values from list a & b where the key is less than or equal to a value, in this case 4 or 9. An ...
4
votes
1answer
224 views

Select elements of list

I have a list of lists list={l1,l2,l3,l4,...}; and two elements e1,e2. I want to select from lists ...
2
votes
1answer
58 views

Manipulating and adding elements in a matrix [duplicate]

I have the following j = {{1, 2}, {3, 2}, {5, 4}, {1, 2}, {3, 2}} k = {1, 2, 3, 4, 5} t = SparseArray[j -> k, Max@j {1, 1}] The above creates a 5x5 matrix ...
0
votes
1answer
32 views

Extending the dimension of matrix and manipulating it

I have the following code a={{1,2},{4,3},{3,2}} b={3,4,5}; x=SparseArray[a->Table[0,{i,Length[a]}]] x=SparseArray[a->(Extract[x,a]+b)]; The above code ...
1
vote
6answers
222 views

Is there an existing way to add a comma between elements of a Scan?

Without thinking, I wrote (the equivalent of) this... ...
7
votes
1answer
86 views

fast complement with tolerance between large lists

I want a fast algorithm to get a list of elements to be kicked out of another list. But the kick out criterion is not the exact equivalence, however has a tolerance. Any two elements close enough are ...
8
votes
0answers
152 views

Efficient way to flatten or transpose-arrayreshape tensors

I have a tensor of dimensions $(2, 100, 100, 2, 100, 100)$ and I want to reshape it to a form of $(2*100*100,2*100*100)$, e.g. Flatten[A,{{1,5,6},{4,2,3}}]. If I ...
13
votes
4answers
366 views

How to evaluate the second argument of Cases only once

I'd like to find a fast but readable way to achieve the following: ...