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
1
vote
1answer
61 views

Compute the length of each string in a set [closed]

Say I have done some computation, and it gives me the following set of string: ...
1
vote
0answers
39 views

How to confirm the list of plot unique

I have a list of plot in a list called modes. I am interested in knowing whether this list is unique or not, meaning all the plots are different from one another. ...
2
votes
2answers
76 views

Use Mathematica to split a sequence according to other two sequences

I want to use Mathematica to solve the following problem: For example I have a sequence 101. I want to compare it with $1101$ and $0101$. The comparison has the following procedure: Check the first ...
0
votes
3answers
49 views

For loop and Append to update a list

I want to update a List, using a For-statement. It doesn't work as I expect. my data is like: ...
1
vote
1answer
91 views

Randomsample without repetition [closed]

I'm looking for a simple way to generate random samples of lists of integers such that each time I sample I'm sure it chooses a new random sample. This is closely related to Picking random items out ...
4
votes
2answers
105 views

Improper formatting for input to ListPlot3D, backwards incompatibility on 12.1?

For context, I am a brand new user to Mathematica using version 12.1 on Linux. I'm looking at an old notebook (2011) that looks at the inviscid burger's equation. The relevant bits from the notebook ...
1
vote
2answers
26 views

Follow-up to “Plot, extract data to file”

This is literally a follow-up to part of Mr.Wizard's answer to: Plot, extract data to a file Specifically in reference to ...
1
vote
1answer
57 views

How to compute k'th tensor power of matrix

Is there a 1-liner to compute $M^{\otimes k}$ where $M$ is some matrix and $\otimes$ is the Kronecker product? The documentation says I can write ...
3
votes
3answers
209 views

Group a list based on multiples of sublists

I have a list of lists like this one, where the sublists vary in length. ...
0
votes
0answers
54 views

Nested operations in Lists as a function of the times it is applied

I have a fixed list labels = Table[i,{i,k}] for some fixed $k$. There is a way of picking some sulists of this list with some property that I am interested in. I ...
1
vote
0answers
39 views

Using the Line command with a bound on distance between points

Suppose I use the Line command applied to a list (or more accurately apply Graphics[Line[list]] or ...
7
votes
3answers
287 views

ReplaceAll, Unexpected output

Each week I import a dataset, and every week the dataset differs in length (the number of records). After the import I need to do some transformations. One of these transformations is the ReplaceAll. ...
5
votes
2answers
318 views

Summing over Partitions

Imagine I have a list of integers $l=\{l_1,l_2,...,l_{50}\}$, say, for example l = RandomInteger[10, 50] and I want to find how many ways there are of summing ...
9
votes
2answers
218 views

How to cut a list by max sum

{5, 10, 3, 8, 9, 8, 8, 4, 1, 7} let maxsum=20, then I get ...
1
vote
2answers
44 views

Is there a workaround to dereference a list element that's the name of an undefined symbol, and iteratively assign values to the symbols in the list?

The title mostly covers what I would like to do. The image below shows in some situations it is possible dereference an element in a list using Evaluate to assign a value: ...
1
vote
1answer
34 views

How to check if a complex number belongs to a quadratic field

I am working with lists of complex numbers and want to be able to determine which out of these lists contains only elements from a certain quadratic field, $\mathbb{Q}(\sqrt D) = \{ a+b\sqrt D :a,b \...
2
votes
1answer
101 views

How do we take certain elements from a list?

Say we have a list ...
0
votes
3answers
77 views

ReplaceAll in list not working as expected [closed]

This is my code. lst = {1, 3, 5}; ReplaceAll[lst, lst[[2]] -> {7, 9, 11}]; lst It is supposed to get output ...
1
vote
4answers
139 views

How would we extract elements of a list greater than a certain value? [closed]

Say we have a list {35,210,67,950,32,365} how would we extract all the elements greater than 100 from this list (using a function)? The desired output would be ...
7
votes
2answers
178 views

Find All Permutations for Multiset

Take a list with repetitions, say {a, a, b, c}, and some permutation thereof, say {c, a, b, a}. I want to know which ...
0
votes
2answers
104 views

How to do two different kinds of binning for a given list of elements?

I have a long list consists of float numbers with some of them duplicated as shown below. I want to divide this list into bins; with equal bin width so that in each bin there might be one or more ...
1
vote
1answer
62 views

How to sort the list A in an increasing order, such that I can modify the other list B with change in element position of list A

I have two lists A and B, I am trying to change modify the elements of list A in an increasing order such that my list B should also be changed according to list A. The node no list is given below. <...
0
votes
3answers
53 views

Manipulating a list while maintaining the nested list structure

Suppose I have a list of pairs of complex numbers with nesting as follows ...
0
votes
0answers
44 views

Solving equations using lists of data

I have a list of pairs of numbers that represent empirical data for U(n) e.g. {{n1,U1}, {n2,U2},...}. Is there a way to use this discrete data set to solve something along the lines of: ...
1
vote
1answer
98 views

How can I find different areas of triangles from a list of points?

If I have a list of points such as {{1, 1}, {4, 7}, {24, 67}, ..., {17, 83}}, how can I find the area of triangles formed by different combinations of these points? ...
1
vote
2answers
169 views

Converting a list to an array

Let's assume that I have a list that I can access like list[[i, j]] How can I convert it to an array such that: ...
1
vote
1answer
75 views

When a list is not a list

When I provide a list of local variables to Module, it complains that it is not a list: v = {x, y}; Module[v, x = 2] ... Module: Local variable specification v is not a List. So my question is how do ...
6
votes
2answers
116 views

Split in non-overlapping sub-lists with elements within an interval from the first member

I want to split a large ordered list into consecutive non-overlapping sub-lists, such that all elements are within an interval from the first member of the sub-list . For example: ...
0
votes
1answer
79 views

Mathematica refuses to distribute a scalar through parentheses

I’m working on a problem involving Kelvin-Helmholtz instability and I’m trying to perform the linearization on Mathematica. For some reason when I get to my first order equation (ε × stuff + O(ε²) == ...
1
vote
2answers
37 views

What does problem statement mean by “using the Table function”? [closed]

Can you help me on the following question? Generate the list {{0}, {0, 2}, {0, 2, 4}, {0, 2, 4, 6}, {0, 2, 4, 6, 8}} using the ...
7
votes
2answers
247 views

How to select the fastest approach for large numerical data computations?

I really love the flexibility of Mathematica: there are several ways to perform one task. However, to get the performance of the intense numeric calculation, it can ...
0
votes
1answer
29 views

Displaying only one component of the list [closed]

I wrote a code which gives me a list which has one coordinate point (for example {{10,11}}) I was wondering how i can only take the y part (which is 11) I tried using: ...
2
votes
2answers
106 views

Using iterative functions to specifically sort a list

The following code sort the list li in a such way that consecutive terms $t_n,t_{n+1}$ are of the from ...{x_,y_}, {y_,z_}.... i....
2
votes
1answer
60 views

Substituting Atoms in .XYZ File

I have a crystal structure in which I'd like to randomize the placement of cations from an initial structure. I have a .xyz file (given here https://pastebin.com/d5UcNr2h) which gives atomic ...
1
vote
0answers
43 views

How to get list[[i,j]] from a list {i,j} [closed]

My problem is more complicated than what follows but this is the minimal working example. Lets say I have: l1={1,2} I have a list: ...
2
votes
3answers
35 views

Select element in a multidimension list containing one element

Imagine that I have a list like: list={{{{1}}}} To access the number 1, I could do list[[1]][[1]][[1]][[1]] Of course it is very ugly but this is how I would do it ...
0
votes
0answers
36 views

Using ListDenistyPlot to Plot 3 Dimensional List

I have a question regarding how to use ListDenistyPlot. I am trying to plot a large list of data (150,000 data points) by using ...
3
votes
1answer
98 views

function over list mathematica

I work on problem that need to define function with two list of data as follow ...
0
votes
1answer
57 views

Generating a list of outputs using For[] Loop

I have a question regarding the use of the For[] loop to generate a list of outputs from a function that generates random outputs. Essentially, creating a sample of ...
5
votes
2answers
125 views

Modify each element depending on previous elements

I'm looking to see if there's a more idiomatic/concise/neat solution than what I have for this. I have a list of boxes with heights and I want to stack them; that is, add to each box the distance to ...
2
votes
1answer
48 views

Replacing $x,y$ in $f(x,y,z)$ with values from a list

I'm sure there is a simple solution to this using map or apply, but its not occurring to me. Suppose I have a function $f(x,y,z)= x+y+z)$ And I want to evaluate $f(x,y,1)$ for $\{x,y\} ∈ \{\{1,2\},\{3,...
1
vote
1answer
66 views

Set part/range of list to specific value

I have a list of tuples like so: ...
4
votes
2answers
97 views

Finding strings which contain a given substring

Using the following commands (which may be inefficient) I can generate all words of length $j$ on the alphabet $\{0,1\}$: sd[st_]:=StringDelete[st, " "] <...
0
votes
2answers
59 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
29 views

Selecting parts of 2d array based on x value

Given a 2d array such as x={{1,2},{2,3},{3,4},{4,5},{5,6}} how would I extract all pairs where the first value is between 2 and 4 such that ...
1
vote
1answer
90 views

Optimizing a slow For loop

I know that this is a "beginner question", and, in fact, I am. I want to improve my code, as it takes really too much time to run. I have already read some other discussions, like here, but ...
1
vote
1answer
42 views

Getting columns (instead of rows) using Reap/Sow

In my program, I'm computing a vector inside a Do loop. The example below is an overly-simplified version, but the structure is the same (the original code can't be ...
0
votes
1answer
41 views

Do or For cycle to have more than ListLinePlot

I have a generic function: f[a_,b_]:=Module[{e,f,g,h}] which returns the scalar g and the list ...
7
votes
5answers
683 views

Remove inner brackets

If I have the result ...
2
votes
2answers
67 views

Sorting a list of pairs so that the larger number in the pair appears first [closed]

Imagine I have this data. I want to sort it so that it takes the form: {{<larger>, <smaller>}, {<larger>, <smaller>}, ...}, Any help ...