Skip to main content

Questions tagged [list-manipulation]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
43 views

Apply an equation based on two sets with different indexes

Apply an equation based on two sets with different indexes Simple example If I have the following elements in the form of two sets with different indexes: $m=\{m_1,m_2,m_3,m_4,m_5\}=\{1,2,2,2,1\}$ $p=\...
Emad kareem's user avatar
7 votes
2 answers
274 views

How can I sort all levels except the innermost level?

How can I sort all levels except the innermost level? The number of levels is unknown. For example: list = {{{d, c}, {b, a}}, {{4, 3}, {2, 1}}} If we needed to ...
internet's user avatar
  • 785
0 votes
2 answers
72 views

Other methods extract the x-coordinates and y-coordinates from a list of multiple coordinate values and list them separately in two individual lists?

x={0.04,0.06,0.04,0.08,0.08,0.05,0.05,0.07,0.07,0.06} y={0.25,0.4,0.22,0.54,0.51,0.34,0.36,0.46,0.42,0.4} The two lists above represent sets of x-coordinates and y-...
csn899's user avatar
  • 4,521
2 votes
3 answers
295 views

Filling the areas enclosed by two curves and calculate them

I know that there are plenty of posts on this, but I just cannot find the right one that solves my issue. The issue is that I have two datasets that I plot them using ...
KratosMath's user avatar
  • 1,309
3 votes
1 answer
227 views

How to optimize performance with DeleteDuplicates?

Does anyone know how to improve this for speed performance? The code works fine, but DeleteDuplicates makes it really slow for large lists. ...
internet's user avatar
  • 785
7 votes
3 answers
412 views

Unsorted Intersection

a = {0, 3, 1, 2, 3}; b = {5, 1, 2, 3, 4, 7}; c = {3, 1, 8, 5}; ...
eldo's user avatar
  • 81.5k
1 vote
1 answer
33 views

Print List based on conditions

How do I print only the values of p which are all True? In addition, is this an efficient use of a Loop in this situation or can this be improved without using a lietral for loop? ...
Steve237's user avatar
  • 491
0 votes
0 answers
67 views

How to speed up this code? (related to list manipulation)

This code is a program for generating a 2D roughness surface. There is no problem when the image size (m * n) is small (e.g., 50 * 50), but when it gets larger (e.g., 500 * 500), errors occur and the ...
GaAs's user avatar
  • 157
2 votes
2 answers
98 views

How can I make a list of exercises from a list of triples to write equation of the plan passing through three points?

I use proflycee to make a tex file like this ...
Thuy Nguyen's user avatar
  • 1,131
6 votes
4 answers
262 views

How can I permute pair of elements in a list?

How can I find all permutations (ways of exchanging positions of pairs in brackets) in a list? The position of elements not in pair should not change. ...
internet's user avatar
  • 785
6 votes
3 answers
173 views

How to replace sequences in a list based on specific patterns?

I have this list: list = {V1, A1, B1, A2, B2, B1 A1, V2} I want to replace sequences like A1, B1 with ...
internet's user avatar
  • 785
0 votes
1 answer
57 views

Finding kernel of a set of polynomial functions [closed]

I have a list of polynomials fi[x_] and polynomial fractions qi[x_] (with i as an iterator) ...
siddhesh's user avatar
0 votes
1 answer
41 views

Defining Objects using a Table or Loop

Suppose I want to define weight[] on a list. For instance I want weight[a]:=3, weight[b]:=5, etc. I tried to do this using the ...
VertexVexed's user avatar
9 votes
7 answers
411 views

Create sublists whose totals exceed a certain threshold and that are as short as possible

list = {2, 1, 8, 10, 1, 4, 4, 5, 3, 4, 4, 11, 12}; th = 10; It is easy to create sublists whose totals don't exceed th: ...
eldo's user avatar
  • 81.5k
9 votes
1 answer
181 views

List[...] + Association[...], or Association[...] + List[...], when does the order matter?

Values of a list can be added to an association's values like so, ...
Carl Verdon's user avatar
2 votes
1 answer
32 views

Table with preset variable is slower than table with explicit number

Why it takes ages to evaluate the second table compared to the first one? The tables are same except that first uses explicit constant 667 while the second one uses ...
azerbajdzan's user avatar
  • 20.1k
1 vote
1 answer
67 views

Function to obtain reflection coefficient of lattice filter

Assume $H(z)=\frac{Y(z)}{X(z)}=\sum _{i=0}^N b_i z^{-i}$ where $b_0=1$ and $b_i$ is real. The corresponding lattice form is \begin{align} v_i[n] = & \ v_{i-1}[n]+k_iw_{i-1}[n-1] \\ w_i[n] = &...
metroidman's user avatar
1 vote
2 answers
51 views

How to get all possible multiplicative combinations of $5$ matrices with unique output

I have a list of five $256 \times 256$ matrices. These are called generator matrices as their multiplicative combinations generate a "Stabilizer group" ...
am567's user avatar
  • 627
3 votes
2 answers
174 views

How can I find all equivalent swapping of some edges in a graph?

This is related to electrical networks, so let me explain a bit about it first. Assume that I have a branch or a loop consisting of only voltage sources in series, as shown below. We know that if we ...
internet's user avatar
  • 785
2 votes
2 answers
83 views

Subsets command not working as expected with dot product of matrices

My understanding is that Subsets[Dot[a,b],{1,2}] gives the output ${a, b, a.b }$ But for some reason, this does not work when I try to do it with matrices. ...
am567's user avatar
  • 627
1 vote
2 answers
101 views

How to transform a list in the following way?

Consider the following list: ...
John Taylor's user avatar
  • 5,887
6 votes
4 answers
345 views

Transform sequence into ragged list

I want to transform seq = {x, 1, 2, x, 3, x, 4, 5, y, y, 67, y}; into {1, 2, {3, {4, 5}}, 67} The only way I found is rather ...
eldo's user avatar
  • 81.5k
0 votes
0 answers
31 views

Neural Network - catenate layer with an input in the form of <|"x"->{"y","z"}|>

I'm doing a research project that requires me to make a custom neural network, and one major challenge I'm facing is that a few pieces of the input data can have varying dimensionality. Specifically, ...
Alex Rosenzweig's user avatar
0 votes
0 answers
52 views

Precision loss when assigning to the elements of a list interpolation function during ParallelDo

A minimal working example of the phenomenon is the following code: ...
Confuse-ray30's user avatar
0 votes
1 answer
59 views

Generate a three-dimensional table with data that satisfy a certain relation between them

I need to generate a 3 dimensional table of two variables x1 and x2 such that for any point x1, x2 must be smaller than x1^2+a^2, where a is some given constant. Something like the following ...
MZP_user's user avatar
12 votes
5 answers
506 views

What is a simple way to copy a partition from one list to another list?

I have two lists of the same length at their bottom level and one contains sublists of various lengths: A={{1,2,3},{4,5,6,7},{8,9}}; B={a,b,c,d,e,f,g,h,i}; Is ...
andring's user avatar
  • 393
4 votes
4 answers
298 views

Replacing string values with one of the sequence-functions

Given the following list of rules (which might contain duplicate keys), I want to replace the string values with the first preceding numerical value. ...
eldo's user avatar
  • 81.5k
1 vote
2 answers
87 views

How to find all the possible products from a list of commutative $2 \times 2$ matrices?

Say if I have a list of commutative $2 \times 2$ matrices. I'll call these $2 \times 2$ matrices $A, B, C, D$. Mylist=List[A,B,C,D] Say if I want to find all ...
am567's user avatar
  • 627
4 votes
5 answers
378 views

Can I merge two tables into one?

I'm using Table to generate such a lattice ...
vector's user avatar
  • 243
3 votes
3 answers
107 views

Extract doi from a text string

I have a large list with bibliometric information including the doi like this example: ...
M.A.'s user avatar
  • 731
0 votes
1 answer
44 views

Is there a simple way to generate a non-uniformly divided interval according to an arbitrary division function?

I often encounter the need to non-uniformly divide an interval. For example, in the code below, I already have a uniformly divided interval teven with [t0, t1] and ...
xinxin guo's user avatar
  • 1,401
3 votes
7 answers
432 views

Extract result of Reap in a natural way no matter if it's empty

This feature has long troubled me, I would like to share it. If Reap has non-empty set of sown, result looks like: ...
lesobrod's user avatar
  • 1,849
3 votes
3 answers
147 views

Recovering indices from an expression

I have a long list and one element in that list is: U[1, 3] U[1, 4] U[1, 5] U[2, 2] U[3, 1] All entries of the list have the same structure of products of U[i,j]'s. In the current instance this is ...
ZeroTheHero's user avatar
6 votes
5 answers
333 views

Counting consecutive units in nested lists

I have nested lists which consist of a series of 1s followed by a series of 0s. p = Table[PerfectNumber[n], {n, 5}]; i = IntegerDigits[p, 2] which results in: {{1,...
stevenvh's user avatar
  • 6,968
2 votes
0 answers
87 views

How to push the performance of this compiled function

I have the function optvals solving for two variables. For the given example of variables, I need the program to run atmost in a millisecond. The main part of the ...
Dotman's user avatar
  • 496
1 vote
0 answers
61 views

How can I efficiently gather similar lists?

I want to gather similar lists by the function sameQ below. Gather works well here, but it's too slow for large data. My real <...
internet's user avatar
  • 785
4 votes
1 answer
109 views

Generate a List of Lists from Two Lists for Histogram Input

I have two lists of equal length: ...
anonmous's user avatar
1 vote
1 answer
87 views

How to speed up generating and filtering large lists of numbers?

I have the following code where I brute force search for two variables. list gives a list of 3 dimensional vectors, say {x,y,z}. ...
Dotman's user avatar
  • 496
1 vote
1 answer
73 views

All possible tuples satisfying conditions

Let $\beta = (\beta_1, \beta_2, \ldots)$ be any given sequence of non-negative integers with all but finitely many $\beta_i$ zero. I want to collect all possible tuples $\beta^{\prime}= (\beta_1^{\...
Anantadulal paul's user avatar
3 votes
3 answers
164 views

How to retrieve the index of a subset in Subsets[list,nspec,{s}]?

Subsets[Range[2000], {4}, {n}] would give the $s^{th}$ subset of the Subsets[Range[2000], {4}]. For example, ...
internet's user avatar
  • 785
1 vote
0 answers
111 views

Implicit Runge Kutta for system of ODEs [closed]

I am trying to build a module that solves a system of ODEs using the implicit Runge-Kutta method but it seems that I have an issue with the convergence condition. Where might the problem be? This is ...
Elis's user avatar
  • 11
3 votes
1 answer
129 views

Nested integration of the list of functions returns error

I have a list of expressions which I would like to integrate by nested integration. For any element from the list it works without issues (see end of the post), however, when I apply nested ...
seva011's user avatar
  • 336
1 vote
0 answers
58 views

Random replacement in array

In the spirit of this interesting article of Stephen Wolfram I also decided to study some issues related to mutations. I’m working with simple {0,1} arrays and I’ve ...
lesobrod's user avatar
  • 1,849
2 votes
1 answer
109 views

Outer function for nested list

I have the following routine where I build a pair of function name lists {Flist, Klist} and 1D argument list {a1,a2,a3,a4,a5}: <...
seva011's user avatar
  • 336
1 vote
1 answer
61 views

Define certain argument in functions which depend on several arguments and built in a list

I got confused working with list of functions of two variables. I construct few lists of functions, one is vector of functions List1 and another is 2D list of ...
seva011's user avatar
  • 336
5 votes
1 answer
161 views

Find permutation that satisfies conditions

Suppose you what to find a permutation of integers {1, 2, ..., 13} that satisfy some rules. Rules can be found in variable rules....
azerbajdzan's user avatar
  • 20.1k
1 vote
2 answers
145 views

Strange behavior of a list manipulation

This is a list of data obtained from numerical calculation, in which the 2nd element in all sublists are the same: ...
lxy's user avatar
  • 189
1 vote
1 answer
67 views

Using List in an Optimisation Problem

I have been adding various constraints to an existing optimiser and came across an issue. My latest constraints requires me to determine a conditional cumulative sum per below. There was an error and ...
legendary kaya's user avatar
0 votes
0 answers
37 views

Plotting a different data set

I am trying to plot the following list in which for each value of x point, we have three different values for the y point list={{1,{1,2,3}},{2,{2,3,4}},{3,{5,6,7}}; ...
sined's user avatar
  • 583
0 votes
1 answer
53 views

Specific array filtering - code optimization

I have a nested list where all sublists have a length 2, eg: {{1,2}, {1,1}, {3,4}, {3,5}, ...} I need to filter it for two requirements: Delete all sub-lists ...
lesobrod's user avatar
  • 1,849

1
2 3 4 5
193