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
3 votes
5 answers
244 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 ...
4 votes
4 answers
787 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 $...
2 votes
2 answers
75 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 get rid of the lists that have more ...
4 votes
3 answers
313 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 ...
3 votes
3 answers
76 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
448 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
51 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
465 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 ...
1 vote
1 answer
57 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
494 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
303 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
328 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 {} ...
3 votes
3 answers
104 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
485 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
225 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
64 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
165 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
214 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
693 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 ...
4 votes
2 answers
2k views

How to label maximum and minimum points on a DateListPlot

I have a list of data points acquired once per day. I want to plot this list of points in Mathematica such that the maximum and minimum points are identified by e.g., a ...
16 votes
10 answers
4k views

Delete zero rows in a matrix

If there is a matrix with some of its rows equal to zero: (its zero rows are randomly distributed and does not have an ordered arrangement): same as: ...
3 votes
1 answer
76 views

Quickly processing long lists using SequencePosition

Overview SequencePosition does exactly what I need; however, it seems to be very slow for long lists. Is there an input option that would allow it to process faster? Or, perhaps an alternative ...
20 votes
9 answers
2k views

Find second largest elements in list

Given a list: lis = {37.21, 37.21, 37.2, 44, 44, 44, 101, 101} What is a simple way to extract the second largest elements? ...
1 vote
0 answers
77 views

How to efficiently calculate matrix operations when the elements are defined as functions?

I'm trying to calculate the one-body density matrix of a system of particles as described in this article, given in equations 14 and 15. Here, is my code but it seems very slow. Is there any efficient ...
8 votes
5 answers
283 views

Ordering with repeats

A quick question on list ordering, how can I easily get the ordering of the list, so that, for {0, Sqrt[3], 2 Sqrt[3], Sqrt[3], 3, 2 Sqrt[3]} I get ...
7 votes
1 answer
491 views

How does this code work?

I saw this thread and upvoted many answers there. Below is the answer by kglr (not my most favorite answer there, but it looks fun). I wonder if anyone could help ...
1 vote
5 answers
110 views

Manipulation Table

I have a table 9x10000, and I need to manipulate in the following way: if one element of the fifth line is equal to zero, the corresponding columns has to be deleted, otherwise it has to be left. I ...
4 votes
6 answers
151 views

Delete sublists of list with given properties

I have a list of the form list={list1,list2,...}, where list1 is of the form {a,b,c,d} and ...
3 votes
3 answers
54 views

Minimum value of every group in table

I have a table with this format. How can I get the minimum value of every group and put it in another list? ...
8 votes
5 answers
124 views

Removing specific sublists

I have a program that generates a list of specific 3-tuples of integers. A typical output is as follows: ...
3 votes
2 answers
599 views

Generating a random walk that can move right, left, up and down

Suppose that we have a dice with 4 faces. If the dice lands on: the person will move to the right the person will move to the left the person will move upward the person will move downward The ...
8 votes
7 answers
156 views

Conditional column extraction

Let $A$ be the following matrix A = {{1, 0, 9}, {5, 0, 6}, {4, 1, 9}, {7, 0, 11}, {8, 1, 2}} and let $B$ be the matrix that comes from $A$ with ...
5 votes
7 answers
419 views

The position of some lists in a list

I have a list of lists: ...
0 votes
1 answer
106 views

Sorting a list according to the position of elements

I have a list of elements, which I want to sort according to the even/odd numbered positions of elements. Basically creating two lists out of one, respectively having elements placed at even/odd ...

1
2 3 4 5
190