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
1answer
43 views

How to apply color gradient in listplot based on the density of points

I have a list of points ( a list with sub lists which are {x,y} coordinates. I would like to have a listplot where the areas with higher density of points are in darker colors and areas with lower ...
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
289 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
320 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
221 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
48 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
36 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
104 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
150 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
183 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
3answers
123 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
63 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
54 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
99 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
176 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
76 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
121 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
82 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
252 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
30 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
61 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
36 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
99 views

function over list mathematica

I work on problem that need to define function with two list of data as follow ...
0
votes
1answer
60 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
126 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
49 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
69 views

Set part/range of list to specific value

I have a list of tuples like so: ...
4
votes
2answers
100 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
69 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
30 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
92 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
46 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
42 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
685 views

Remove inner brackets

If I have the result ...
2
votes
2answers
68 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 ...
0
votes
1answer
33 views

Assume symmetric F[a,b] = F[b,a] when CountDistinct and similar functions

I wonder how I can tell Mathematica to regard the following expressions: F[a,b] and F[b,a] as being equal, so for example ...
3
votes
2answers
74 views

Join sublists on condition

I have a nested list of integers and want to join any sublist matching a condition to its left neighbouring sublist, iteratively. Conveniently, the joining condition is whether the length of the list ...
0
votes
0answers
47 views

Long execution time using position

I have two lists, for example: List1={2,4,6,8,10,12} List2={4,10,12} I want to find the positions in List1 such that the element at that position is equal to the ...
0
votes
1answer
37 views

Using and Naming different sets of data in a manipulated chart/plot

I am trying to visualize advertisement data from amazon which is comprised of a dozen or so campaigns, each of which has three subgroups and each subgroup has its own performance data (metrics). ...
0
votes
1answer
47 views

Performing mathematical operation on the y coordinates in a list of coordinates

I have a list that contains a set of coordinates in the form {{x1,y1}, {x2,y2}, ...}. I want to edit the list in manner that it takes the log() of all the y coordinates only. Essentially, I want ...
3
votes
1answer
68 views

selective deletion of list members

I have a list and need to remove certain members of the list. lis = {f1,a,b,c,d,f2,e,g,h,i,f1,j,k,l,m,f2,n,o} I need to remove each occurrence of f1 and the ...
0
votes
1answer
22 views

How to store outputs as coordinates and use ListPlot to plot them?

so I have a program that outputs a desired value for incrementing values of alpha. Right now, my program prints a list of these for 40 values of alpha in the form {alpha, newValue}. ...
0
votes
2answers
57 views

Using Table to iterate over two lists element by element instead of as a matrix

So I have two lists generated in the following fashion, I don't know if it's the most efficent way to get these, but that's beside the point right now. ...
0
votes
0answers
65 views

Why does Log[Abs[#]] return a complex number?

For a nonzero number $x$, $\log|x|$ should be a real number. Why does the following NestList contain non-real numbers when no numbers involved are close to zero? Is it a bug? ...

1
3 4
5
6 7
138