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
4
votes
2answers
122 views

How to apply Cases on multiple parts of sublists?

I have the following data sol={{2063, 853}, {2066, 855}, {2069, 857}, {2072, 859}} I can find prime-pairs by ...
4
votes
2answers
56 views

Replace Solution arrow in list of list

I have solutions like ...
3
votes
2answers
64 views

Shifting fit and its data on x axis

I have the following list: ...
7
votes
4answers
154 views

How to handle Part function error when position does not exist?

Say a list list={{1,2},{3,4}}, list[[1]] and list[[2]] works. But ...
6
votes
2answers
98 views

How to group points based on mesh primitive membership

As a simple example of what I want to do, let's say I have a Voronoi mesh in a $10\times10$ area with $10$ random "seed points": ...
1
vote
0answers
35 views

MapAT and GeoPosition

I just experienced a problem applying GeopPosition via MapAt. Here a MWE. Given a list of data: ...
9
votes
1answer
99 views

SequenceCases does something odd with RuleDelayed arguments

I have a list of stuff. list = {a, b, b, a, b, a, a, a, b, a}; I want to split it up into subsequences where a single a is ...
4
votes
2answers
169 views

How can I sort a nested list?

I have a nested list of the form: ...
1
vote
1answer
59 views

Constructing a List of Functions

I would like to construct a list of Functions that can be used like: F[z][[i]] Where one can choose between list elements with ...
4
votes
3answers
145 views

Searching for nodes in the network

Let consider the network ('graph'): ...
3
votes
1answer
56 views

Question about iterator

I am new to Mathematica. I just want to evaluate a 2x2 Jacobian and then evaluate it on different values of the two variables x and y. The values I want to use to evaluate the Jacobian are the result ...
6
votes
2answers
126 views

Mapping between lists and Mapping Formats

I've been writing a conversion 'script' between two robot description formats and thought I would try out Mathematica as I thought it sounded pretty awesome. Although by this point I should have done ...
0
votes
0answers
29 views

Redefine a function on certain values

This question is related to Zero-dimensional matrices, in particular to the answer https://mathematica.stackexchange.com/a/39543/42722. In Mathematica $0 \times n$-matrices are not well-defined, so I ...
1
vote
2answers
31 views

Using a list to make a contour plot of multiple values

I'm trying to make a contour plot for multiple values of the same function. To accomplish that, I'm doing the following: ...
1
vote
1answer
45 views

Creating a For Loop to simulate matrix changes

I'm trying to create a For loop (Using the For syntax is a necessity for the future work I'd be performing) for a matrix given by the following lines of code: ...
1
vote
3answers
85 views

How to find a number that multiplied to a list, returns an all-integer list

I do not know how to code the following. Suppose you have a list lst={x1,...,xn}and you need to find a number $Z$, to a given digits precision such that ...
2
votes
2answers
46 views
3
votes
0answers
37 views

Transforming a checkerboard using Transpose and ReshapeLayers

In the paper for RealNVP, they introduce a "squeezing" operation that takes a matrix and transforms it to have more channels, according to the following transformation (before and after): As you can ...
5
votes
4answers
100 views

Grouping and repeating the grouped rows inside a matrix

I'm interested in finding the quickest way of grouping the rows of a large matrix in sub-groups based on the position of non-zero elements in the first column and then repeating them number of times ...
5
votes
1answer
46 views

Create block matrix with secondary diagonals using Band function

Given matrices m1, ... , mk and matrices n1, ... , nk-1, I would like to define a block matrix $$ m=\left( \begin{array}{rrrr}m1 ...
0
votes
1answer
31 views

ListPlot will not plot my two dimensional array

I am working in an experimental data analysis, the equipment I used handed me the data in txt. format, to import to Mathematica I used the following: ...
0
votes
0answers
46 views

Realization of fake infinite list

I would like to define an "infinite list" list in the following sense: first, we set a finite number of elements list[[k_i]] (...
7
votes
1answer
185 views

And@@(f/@list) without evaluating f for the whole list

And[f[1],f[2]] doesn't evaluate f[2] if f[1] is false, but ...
5
votes
2answers
117 views

Counting possible tuples on a list

Suppose I have the following list: ...
3
votes
1answer
83 views

Creating a custom list plot with dates

We have the following data ...
1
vote
1answer
56 views

Parallel computation gives different result

This is a followup question to this one. Following the comment, I used the code in this answer in this way: ...
0
votes
2answers
58 views

Normalize y-values from lists

I have have some (x,y) lists generated by: Do[Spec[2*i] = AllData[[All, (2*i + 1) ;; (2*i + 2)]], {i, 0, 10}]; So that Spec[0], Spec[2] ... Spec[20] are (x,y) ...
2
votes
1answer
45 views

Creating a function with a list as an input

I have to create a function that takes a list as its input. The conditions are as follows: if the list contains a 1 before a 2, the output should be a new list where the 1 and the 2 have changed ...
4
votes
2answers
162 views

How to transform list with index numbers

I have a list which looks like this: {1,2,1,2,1,2} I want to transform it into list that looks like this: ...
0
votes
2answers
69 views

How to normalize vector to sum to 1? [closed]

I want to create an array/vector such that all the values sum up to 1. I can't do this for some reason when I do the following: ...
1
vote
1answer
39 views

Make a new list of rules by matching up keys from two given lists of rules

Consider two lists of rules: ...
6
votes
3answers
343 views

How do I modify a symmetric matrix while maintaining symmetry?

I'm trying to figure out how to create a For loop for a symmetric matrix. I have a 5 $ \times $ 5 symmetric matrix consisting of 1's and 0's and I'm trying to ...
1
vote
1answer
32 views

Pick out two related elements from a list using criterion

Suppose I have a list: $lst= \{\{k_1, g_1\},\{k_2,g_2\},...,\{k_{max},g_{max}\},...,\{k_n,g_n\}\}$ Here $\{k_{max},g_{max}\}$ is a special element, in which $g_{max}$ is the maximum of all $g_{i}$ ...
7
votes
2answers
145 views

Easily limit list length without getting error if list is empty?

I often need to constrain the length of a list when previewing a list, either in Manipulate or for getting a better sense of the output. Without it, the output may ...
7
votes
1answer
138 views

Fastest way of numerically creating a list of dot products

I have a list of numerical complex 2x2 matrices list = {M[4,3],T[3],M[3,2],T[2],M[2,1],T[1]} (in reality this list contains over 1000 matrices and I have to do ...
4
votes
1answer
75 views

Why the difference in performance? Array vs List and `Delete` vs `Nothing`

In a previous question I was warned against the use of Nothing to delete elements from a list, and rather use Delete. Being of ...
2
votes
1answer
33 views

Getting general::write error while making list in for loop [closed]

So I solved following ODE $$\frac{d^2y}{dx^2}+(a^2 (5+4\tanh( x))+b^2)y=0$$ in Mathematica. Now I need to create a list for further manipulation using the above solution. I wrote the following code: <...
1
vote
1answer
39 views

Using MinimumBandwidthOrdering to restructure a correlation matrix

I am trying to restructure a correlation matrix such that the variables with the strongest correlations are grouped together Needs["GraphUtilities`"] These are ...
0
votes
0answers
36 views

How can I rewrite this code so that it gives me the same result in less than one second? [duplicate]

For[i = 1; list = {}, i <= 23456, i++, l = AppendTo[list, i/Pi]]; Total@N@list
17
votes
6answers
1k views

A clean way to conceptually extract Parts from a circular list

I quite often run into a situation where I want to treat a list as a circular (repeating) list, and want to take a specific sublist of it, such as... One past the end of the list: ...
7
votes
1answer
97 views

How would you explain Nothing[] weirdness? [duplicate]

I would like to use Nothing[] to make some elements of a list invisible. (The intended use is to remove a few unwanted points from a ...
2
votes
1answer
52 views

Reassign Lists after adding new elements to the same Symbol

I try to Reassign Lists after adding new Elements as the following Examples: m1 = Table[{"A", "B"}, 3]; m2 = Table[{"C", "D"}, 4]; n1 = Range[3]; n2 = Range[4]; ...
3
votes
1answer
55 views

Generating vectors with small inner products in a large vector space

I want to generate a large number $k$ of vectors of norm 1 in a $d$ dimensional vector space such that $k>d$. I want these vectors to have inner products as small as possible. A crude way is to ...
3
votes
2answers
77 views

How to separate and re-order a list of points?

Suppose that we have a list of points. By plotting them we find two curves but the points are in a sequence of first fixing $x$ and then increasing $y$, next fixing $x+dx$ and then increasing $y$ and ...
2
votes
1answer
55 views

Using Predict to fill in missing data

I am attempting to use Predict[] to fill in the missing data in the dataset below; ...
11
votes
5answers
446 views

How to remove duplicate elements [duplicate]

How to remove duplicate elements? I want to delete all the same elements in a list. For example, list {1,2,1,2,3,4,5,1}, I want to get ...
3
votes
1answer
129 views

How to turn {2, 9, 3, 16, 81, 0.09} /. {x_Prime -> Sqrt[x]} into {Sqrt[2],9,Sqrt[3],16,81,0.09} [closed]

How to make this below work? Input {2, 9, 3, 16, 81, 0.09} /. {x_Prime -> Sqrt[x]} I wanna turn this list into {Sqrt[2],9,Sqrt[3],16,81,0.09}
9
votes
2answers
758 views

Why does {2, 9, 3, 16, 81, 0.09} //. {x_Integer -> Sqrt[x]} evaluate infinite times? [closed]

Here is my code. {2, 9, 3, 16, 81, 0.09} //. {x_Integer -> Sqrt[x]} The pop-up message ReplaceRepeated::rrlim suggests ...
1
vote
1answer
39 views

Use StringSplit with a Whitelist

I have a string like this: animals = {"Cow and Milk and Chicken and Egg and Pig and Sheep"}; Now I want to use StringSplit...
6
votes
3answers
68 views

Sorting list on multiple criteria based on means of subgroups

I have a set of records where each record is for a particular item. An item is a member of a particular subgroup and a subgroup is a member of a particular group. One item is always a member of a ...

1
3 4
5
6 7
126