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

How would you perform a simple operation on two adjacent elements of a list?

I have an arbitrary list of elements: list = {a, b, c, d, e, f} How would I produce: ...
0 votes
1 answer
99 views

Bin edges from BinCounts

I'm working with a set of data binning values. I'm using bincount and binlists to find bins that meet a certain criteria and then testing a list to see which are within one of those bins. This list of ...
18 votes
2 answers
489 views

Deleting duplicates after n-occurrences

As a generalization of DeleteDuplicates, I want to delete duplicates from a list, but only after n number of duplicates. Say, <...
4 votes
7 answers
306 views

Finding equal values in a list

Is there a way to take equal elements out of a list and their position??? An example can be ...
3 votes
2 answers
101 views

Rows within a norm

Is there a way to take a matrix and select the rows (or columns) with norm lesser than a certain amount max. Thanks
1 vote
1 answer
50 views

Incrementing Numbers

I want to take a prime number p0 = 3, add 2 to it to get a new number p1 = 5, then add four to p1 to get p2, then add 6 to p2 to get p3, etc for a total of 50 times. How do I do that and place my ...
7 votes
1 answer
143 views

Fast Sparse Tensor Addition

How can one do a fast sparse tensor addition? Below, I have the following code: We first generate 3 random sparse 1000x1000x1000 tensors with 10^6 entries each. Then, I want to add them. But the usual ...
6 votes
3 answers
189 views

Fill space between two BezierCurves with random points

I asked a question about filling the space between two curves (Sin and Cos) with random points and the answer I received does ...
8 votes
5 answers
491 views

How to verify whether list A contains all elements of list B?

I want to determine whether a list A contains all the elements in the list B (including duplicate elements). For example, for <...
6 votes
7 answers
290 views

Partition sublists of a list

Let's say I have the following list: l1={{2015, 5, 6, 13692}, {2015, 5, 7, 13715}, {2015, 5, 10, 13274}, {2015, 5, 11, 13581}, {2015, 5, 12, 13609}}; How is ...
7 votes
7 answers
176 views

How to remove sublists whose difference of two elements is either 1 or 11?

I want to create a list of 3-element subsets of $\{1,2,\cdots,12\}$ where no two elements in each subset can have difference of 1 or 11. I am trying to solve the following: Find the number of all ...
9 votes
4 answers
881 views

Conditionally replace rows in lists

I have a sequence of matrices/lists ...
4 votes
4 answers
614 views

Replace multiple elements at different positions

I have a list a = {0, 0, 0, 0, 0}; and now I would like to make only those elements 100 at the positions in pu = {1,4,5}; So I ...
5 votes
3 answers
99 views

How to use Cases to delete specific lists from a nested list

To simplify things, let's say that I have a list: aList = {{1,2,3,4},{2,2,6,6},{6,9,8,7},{6,6,6,3}} and I want to use Cases to ...
9 votes
6 answers
729 views

Applying a function to every item in a column of a matrix

A problem that arises more often than I care for is that I want to modify specific elements nested lists. Examples may be wanting to add 1 to the second value, get ...
5 votes
7 answers
273 views

How to remove sublists whose last digit is odd?

I want to remove any sub-lists whose last digit is odd. My attempt below does not look elegant because I convert each sub-list of digits to a number first and then remove the odd numbers. Question How ...
6 votes
5 answers
138 views

How to rearrange sublists based upon the element in the first position?

If I have the following code: ...
5 votes
4 answers
803 views

Changing value of specific element in an array. (Converting code from MATLAB to Mathematica)

Can we change the value of a specific element of an array in Mathematica? Basically, I have the following given MATLAB script which writes a big 3N-by-3N matrix $h$ by combining two 3-by-3 matrices $...
5 votes
3 answers
320 views

Set value in a list at given position

Consider r = Array[Total[{##}] &, {3, 3}] (*{{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}*) pos = {{1, 1}, {2, 2}}; vals={100,200} This ...
4 votes
3 answers
79 views

Using Select with a function on 3d Table

From the following 3d-Table t1={{{1, 1}, {2, 1}, {3, 4/3}}, {{1, 0}, {2, 1/2}, {3, 1}}, {{1, -1}, {2, 0}, {3, 2/3}}} I want to ...
7 votes
4 answers
473 views

Optimal Solution for OddsBeforeEvens Wolfram Challenge

Odds before Evens Given a list of integers, rearrange them so that all of the odd integers appear before all of the even integers, without otherwise changing the order. An obvious solution is ...
0 votes
0 answers
55 views

Total applied to the lists: length of the object

My goal is to evaluate the total of each line of the following list: ...
8 votes
6 answers
467 views

How to classify an ordered ascending {0, 5, 5, 10, 19, 22, 23} into several classes {{0,9},{10,19}, ...}?

I attempted to classify an increasingly ordered list into several classes to make frequency distribution table. I am faced with a difficulty to nest two pure functions: one for ...
2 votes
1 answer
73 views

Tell Mathematica that the output of a function is a List / Vector

I have a function (Piecewise) that returns a list, e.g.: F[x_] := Piecewise[{{{x^2, x}, x < 0}, {{x, x^2}, x > 0}}, {0, 0}]; I would like to add another list ...
10 votes
6 answers
496 views

Non uniform Riffle of two lists

Let's say I have x = {b1, b2} and y = {{a1, a2}, {a3, a4}, {a5, a6}} I want to produce the riffle'd list ...
5 votes
3 answers
305 views

Join two lists by using the first element

I have two lists, which as a simple example can take the form: l1 = {{a1,a2,a3},{b1,b2,b3},{c1,c2,c3}} l2 = {{a1,n1},{c1,n2}} How can I merge them by the first ...
12 votes
4 answers
329 views

Use Cases with empty cells in the list

I work with a complex dataset. The most simple form of this list looks like: dat1 = {{a, b, c, {}}, {d, e, f, {1}}, {h, i, j, {2}}} I want to select the nested {} ...
4 votes
3 answers
110 views

How can I construct an equivalence relation in the form of a 0-1 matrix from a set partition?

I have a partition of a set {1, 2, ..., n}. I would like to construct the equivalence relation that corresponds to the set partition in the form of an $n \times n$ ...
3 votes
7 answers
212 views

List operations: how to combine two lists (pattern given)?

Two lists (matrixes) are given: a = {{x1, y1}, {x2, y2}, {x3, y3}}; b = {{u1, v1}, {u2, v2}, {u3, v3}}; Expected return: ...
10 votes
9 answers
385 views

Take elements from a list based on two criteria

I am trying to take elements from a list of tuples using 2 criteria. An example of the list is: list={{-1, -1}, {-1, 1}, {1, 1}, {1, -1}, {1, (1 + I)/Sqrt[2]}} ...
8 votes
8 answers
486 views

How to apply a function to one part while keeping the rest?

I have a list and want to apply a function just on the second Part and keep the rest. t1 = Table[{k, 2^k + 1}, {k, 2, 7}] ...
7 votes
5 answers
222 views

Question on using Array

I could do vars3d = Array[Through[{x, y, z}@#] &, 5] to obtain ...
8 votes
6 answers
398 views

When applying (@@) a function to a list of potential arguments, how can Slot be used to take the last argument?

I wouldn't be surprised if the title question is confusing, so I'll try to elaborate by way of example. Consider the list ...
6 votes
4 answers
247 views

How do I replace specific sequences of a sublist without changing the level of the list?

Suppose I have a list of multiple sublists: testlist={{1,1,1,0,0,0,1,1,1,0,1,1},{1,0,0,1,1,1,1,0,1,1,1,0}} I want to replace given sequences without creating new ...
4 votes
4 answers
227 views

How do you reorder a sublist of strings, within a list?

I have a list that looks like this: ...
5 votes
5 answers
149 views

Create a list that always ends with two 1's but starts with a variable amount of 0's

I want to create a variable list like this: {0, 0, ..., 0, 0, 1, 1} This list would grow list this, starting with no 0's, but then gaining more 0's to the left the ...
1 vote
0 answers
66 views

Sum of disjoint product of sets [closed]

If we have the following sets and we need to apply the Sum of disjoint product property to them, as in the following example: Take: $$P_1=\{x_1 x_4\}$$ $$P_2=\{x_2 x_5\}$$ $$P_3=\{x_1 x_3 x_5\}$$ <...
7 votes
3 answers
368 views

How to pass arguments to the list of functions?

Suppose I have a list of functions: functions = {f, g, h, ...} And all of those functions are in form of f[x_ , y_]. For ...
8 votes
3 answers
140 views

Combine list elements preceding a specific element

Consider the following list: {"END", "END", "a", "b", "END", "p", "q", "END", "t", "END"} I want to combine elements that precede the marker element ...
4 votes
3 answers
166 views

Map substitution of variable in expression

If I have an expression involving a variable x, like 2x+1, and I have a list of different possible ...
6 votes
4 answers
216 views

Display Table output as a grid of points

I want to create a Grid or Plot (or equivalent) from the following Table: ...
13 votes
10 answers
2k views

Subtracting from a specific column

I have a huge list with huge sublists of the form list={{a,b,c,d},{e,f,g,h},{i,j,k,l}} I am looking for a way to manipulate these sublists based on the positions ...
9 votes
6 answers
197 views

How can I add or remove the element in the sub-lists, whose length are different?

If there are lists with different lengths of sublists like below, ...
4 votes
5 answers
107 views

Conditionally extracting data from long lists

I need to make a fit on a small part of my data list. To do so I need to extract data setting a condition. Example: From the list below I would like to create a new list that contains only data whose ...
8 votes
4 answers
696 views

Simple way to convert expression to a list?

I know that I can convert an expression to list by List @@ expr But this does not work if expr is atomic, e.g., ...
7 votes
5 answers
194 views

How do you apply "Pick" to multiple sublists?

I have the following list: lis1={{{A3,T3},{A3,T4}},{{A3,T3}},{{A3,T3},{A4,T4},{A3,T1}}} Which is also accompanied by an ...
9 votes
3 answers
186 views

How do you take position "x" in multiple sublists to make a new list?

this is a rather rudimentary question, but I was wondering if there are more efficient ways to do the following: dd = {{{12, 3, 5}, {14, 10, 11}}, {{15, 76, 65}}} ...
7 votes
5 answers
271 views

Threading a list of functions over a list of arguments

I want to produce {Foo[a,b, c], Goo[a, b, c], Hoo[a, b, c]}. However my attempt below ...
9 votes
7 answers
1k views

Merging the last columns of two lists under a rule

If I have two lists whose first columns are identical, such as: ...
8 votes
11 answers
4k views

Subtract lists' elements

I have 2 lists, that have the following form: List1 = {{0.0, val10}, {0.1, val11}, {0.2, val12},...} List2 = {{0.0, val20}, {0.1, val21}, {0.2, val22},...} I ...

1
2 3 4 5
190