Questions tagged [list-manipulation]
Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.
6,760
questions
3
votes
3answers
40 views
generating lists of integers with constraint
Suppose you have the list $a=(k_1,k_2,k_3, \dots, k_N)$ such that $k_{i}\; (i=1,\ldots, N)$ are non negative integers. How can you get all the lists that satisfy the constraint $\sum_{i=1}^{N} k_{i}=M$...
1
vote
1answer
31 views
11
votes
9answers
864 views
2
votes
2answers
171 views
Delete a range of elements from a list [closed]
If I have a list of 100 integers, say {1,2...100}, and I wished to delete all elements that are greater than a random integer $n$, what command should I use for ...
3
votes
2answers
146 views
Extract Parts of a Function
I have an expression of the form
a Integrate[b[t], {t, 0, x}]
and I would like to take the coefficient $a$, save it to a list, take the $b(t)$ out of the ...
3
votes
2answers
133 views
Replacing a random ith row and column from a matrix
Currently I am trying to delete a randomly-chosen $i^{th}$ row and column from a square $n \times n$ matrix $A$. So far I come up with the following code:
...
5
votes
4answers
137 views
How to drop/extract elements of a list which starts with Plus
I have the following list :
list={a^2, b^2, a^-1, a^2+b^2, (a+b+c)^-1, (a+b-c)^-2}
Do[Print[list[[i]]//FullForm],{i,1,Length[list]}]
I want to break this list into ...
5
votes
1answer
109 views
ReplacePart to substitute a row in a Matrix
I have a very large n x n matrix from which I want to take a row i from and substitute every element with 0. When I try the below command however, the ith row is not replaced by a list of n zeros but ...
2
votes
1answer
198 views
0
votes
1answer
78 views
Improve running speed of FullSimplify function
How can I make this code faster? The checking with FullSimplify takes a lot of time.
...
1
vote
2answers
94 views
Can one make `Do'-Loops of arbitrary depth?
In the documentation for the Do[...] function, a loop of nesting up to any number of layers is supported. But to apply their function, one needs to know ahead of time how many layers of loops they're ...
0
votes
0answers
56 views
Correct way to format numbers
I have defined the following function:
randvec[mag_]:= mag Normalize[Table[RandomReal[], {j, 1, 4}]]
I would like to format the numbers in the list so that they ...
2
votes
1answer
53 views
List of all possible unions of given sets
I'm trying to generate a list of all possible unions of some sets to generate a topological space from a given basic sets.
For ex: Given
{1}, {2}, {4}, {1,3}
I ...
0
votes
2answers
70 views
How to generate random vectors without repetition?
Say we have three elements, 0,1,2 and we want to generate 1000 random vectors of length 7 with these elements, i.e.
{2,1,0,0,0,0,2}
How can we do this without ...
1
vote
1answer
57 views
0
votes
0answers
53 views
Appending to a list in a For-loop
I am new to Mathematica. Here is my problem:
Given the matrix
$\qquad M =
\begin{pmatrix}
2 & -1 \\
1 & 2
\end{pmatrix}$,
sum the overlap (inner-product) of it's eigenvectors
$\qquad \bigg\{\...
-1
votes
0answers
45 views
Rotate and translate previously-plotted data
I have the following:
Show[data1, data2, data3,PlotRange -> {All, All}]
where data1, ...
2
votes
1answer
55 views
Removing certain numbers from a list
If I have an list of numbers {1, 2, 4, 70, 11, 20, 56, 79}, is there a way to remove the list {2, 4, 56} from that list?
In my ...
3
votes
1answer
69 views
Remove errors from sublists after Excel import
I have a very long list such as:
https://pastebin.com/9vYDLsVp
At the end of each sublist for some reason I have {,-6}. How can I remove that from each sublist of ...
0
votes
0answers
32 views
Iterating MovingMap with Nest
I am trying to create a background correction inspired by the PyMca strip background method. The data I'm trying to correct is a HPLC chromatogram in the form of a ...
3
votes
1answer
101 views
Build Table of Edge Weight Sums
Is there a convenient way to build a table as generated by the code below where a 5th column (at the far right) could be added to the table that is the sum of the edge weights for the nodes in a given ...
0
votes
0answers
27 views
“Tag List in … is Protected” [closed]
I tried to plot this surface:
scherk5[a_, b_, c_][u_, v_] := {a ArcSinh[u], b *ArcSinh[v], c* ArcSinh[u v]}
I obtain ...
3
votes
3answers
105 views
Alternative to Inner which allows level specification
Is it possible to restrict Inner to a certain level? According to the documentation, the expected behaviour for Inner is to ...
0
votes
1answer
70 views
List Plot Error [closed]
I've produced this simulation of a superhetrodyne radio receiver. I'm pretty sure it's solid for the most part but I'm getting a list plot error.
ListPlot::lpn: {{{1.,0.},{2.,0.00104953},{3.,0....
4
votes
2answers
54 views
Smart under-sampling of a large list of data points
I have dielectric functions of materials as lists of value pairs {{x1, y1}, {x2, y2}, ...} and unfortunately some of them are quite long, which is a bother in ...
0
votes
0answers
30 views
InterpolatingPolynomial: magnitude of coeffictions
I have a list of the type {{x,y},f} and want to get an InterpolatingPolynomial for that list. The x values all run between 1.3 and 2, the y values between 0 and 1. ...
8
votes
3answers
443 views
Improve running speed for DeleteDuplicates
How to make this faster? I want to remove elements that satisfy the condition below but it's way too slow.
...
-1
votes
1answer
47 views
PlotStyle options not working [closed]
I have a list of LogLogListPlots, lets name it 'Collection'. 'Collection' has i elements. When representing them all in just one plot I use:
...
5
votes
6answers
537 views
Representation a matrix as a colored square shape
I am sure that I have accidentaly seen before a way to construct a square shape corresponding to a matrix. For example if we have a 5*5 matrix:
...
4
votes
3answers
220 views
DeleteDuplicates and select which one to delete from a pair
In this case if two lists with the same total then one list is deleted.
Can I add one more condition to choose which one to be deleted, for example the deleted list between the two is the one where ...
6
votes
1answer
77 views
Partitioning a list to several depths
I an aware of the Partition command which partitions a list into sublists. I'm curious as to whether there is an efficient way to partition a list several times ...
1
vote
1answer
49 views
Interactively extracting arbitrary portion of elements from a 2D list
I have a 2D list which can be plotted as follows:
Image 1
Based on the plotted image, I would like to select some of the shapes on the image and extract the data for further analysis, for example,
...
7
votes
4answers
102 views
Take $ n^\text{th} $ sub-list with equal distances
I have been looking at Span, Take, etc. functions but I couldn't figure out how can I extract elements likes this
...
1
vote
1answer
61 views
Sort and extract values in a nested list
I want to sort the following nested list of peak points by the y values while keeping the dimensions consistent.
I then want to extract the x value of the largest and second largest y values (if the ...
1
vote
0answers
42 views
How to specify an element of a list when using RecurrenceTable [duplicate]
My problem is that I'm trying to get a list of refraction angles in a multilayer structure (for the sake of this example - with two types of refraction indices and eleven layers of them). The code is ...
4
votes
0answers
70 views
What exactly is the difference between Part and Extract?
From the statement in the documentation:
Extract[expr,{i,j,ā¦}] is equivalent to Part[expr,i,j,ā¦].
So basically Extract is just a listable version of ...
2
votes
1answer
66 views
Getting 1st element of a nested list, based on criteria for 2nd element [closed]
I have a list such as {{abc,1},{def,2},{ghi,1},{jkl,3}}.
I would like to extract elements that have 1 as the second element (ignoring those that have 2 or 3 as their second element).
In the case ...
4
votes
5answers
322 views
Randomly Choose from list but meet conditions
I have a list of integers from 0-99, but some of the integers have been randomly removed.
I want to pick a random integer that is still in the list, letās call it āaā but if a+1, a+2, and a+3 are not ...
0
votes
2answers
58 views
Import and extract certain column and row
I have a problem with importing and extracting 2nd column in my CSV file. I need to have 3 list, the first one first column except for first row, the second will be second column except for 1st row ...
0
votes
1answer
99 views
0
votes
1answer
137 views
Picking data from a list
For the purpose of my question, I cannot use random data. So the data are provided.
...
5
votes
4answers
186 views
Extract four (von Neumann) neighbors of a matrix entry
Assume I have a $m\times n$ matrix and I would like to extract four neighbors of randomly selected entry of a matrix. I have handled if location is not on the boundary. Any suggestion how to handle it ...
1
vote
1answer
94 views
Extract points from given Line[]
As the title says, I have a Line object like this:
Line[{{1,2,3},{4,5,6},...,{7,8,9}}]
and want to extract certain points. I ...
5
votes
2answers
322 views
Sparse block matrices all wrong
I need to represent $M-\lambda\cdot\textrm{Identity}$ where $M$ is an operator on $V_1\oplus\cdots\oplus V_n$ made from
$$
V_1\xrightarrow{M_1}V_2\xrightarrow{M_2}\cdots\xrightarrow{M_{n-1}}V_n\...
2
votes
0answers
38 views
How to extract the same entries from two tables? [closed]
I have 30000 entries in two tables. Now, I want to extract those two entries which are the same. How can I do it? For example, I have two tables, say T1 and T2;
...
2
votes
2answers
192 views
Given a list of linear equations, what is a neat way to use solve on the equations of this list? [closed]
Suppose I have a list of equations, say {2x+b+3c=3, 7x+2b+c=1, x+b+9c=-2} what is a neat way to use Solve[] on that list? ...
3
votes
1answer
39 views
Removing specific entries from a list
I have the list
L=8;
indx = Range[-Ļ, Ļ, 2 Ļ/L]
(* {-Ļ, -((3 Ļ)/4), -(Ļ/2), -(Ļ/4), 0, Ļ/4, Ļ/2, (3 Ļ)/4, Ļ} *)
Now I want to delete specific elements of this list,...
1
vote
3answers
56 views
A conditional list generator with stored argument values
I have already made this and the question is really about "how to make this faster and more general (to save the 4 keypresses of D,o,[ and ] that have to be made per-parameter)"
The function:...
3
votes
2answers
114 views
Merging pairs of a list with keeping the first elements and adding the second elements
I have a list that was generated by the below code:
Do[
Do[
AppendTo[list, {RandomInteger[i], RandomInteger[j]},
{i, 1, 5}
],
{j, 1, 5}
]
A result can be ...
0
votes
1answer
45 views
Issue with threading matrices
I like this answer, which provides an "autoThread" function for more intelligent threading, but it doesn't work in this example and was hoping for a fix.
So for this code:
...