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
2answers
72 views

NMinimize over a list of integers

I'd like to minimize some function (of 3-4 variables) over a big list of integers, but not consecutive. Like arr = {5, 10, 7, 101,...} I did not understand this ...
4
votes
2answers
164 views

An operation on a list [closed]

I have a nested list, and I want each sublist to be connected by a <-> symbol between the first and third elements and between the second and fourth elements. For example, ...
5
votes
4answers
309 views

List rearranged

I have a very long list from which I will display part of it as, a={{1, {3, 5, 8, 9}}, {2, {4, 6}}, {6, {1}}, {10, {1, 3, 5, 6, 7, 8}}}; For plotting purposes, I ...
2
votes
3answers
85 views

Swapping items in a table

I have a code that generates various tables like ...
6
votes
1answer
79 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 ...
0
votes
0answers
87 views

how to change list of some scalars into vectors?

I have a pair of equations f= {eq1,eq2} that are (x,y) dependent. I take derivative by (x) and (y) for each equation, for example, Grad[f, {x, y}] . {1, 1}] and ...
1
vote
1answer
85 views

Dropping specific elements from list

list[1] = {{1, 1, 0}, {1, 0, 1}, {0, 1, 1}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}}; ...
1
vote
0answers
33 views

How do I input n-Dimensional random numbers into a function accepting n variables [closed]

Apologies if this is overly simple but I wasn't able to find an answer online. Question Say I have a function defined as follows (and not two separate instances of random numbers), ...
0
votes
1answer
81 views

Lists of labelled vectors, how to output a list of tuples which sum to zero

list = {{1, 1, 0}, {1, 0, 1}, {0, 1, 1}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, {-1, 0, 1}, {1, 0,-1}, {-1, 0, -1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1}}; list2 = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}, {-2, ...
1
vote
1answer
52 views

Delete rows from 3D matrix and convert it to 2D matrix

I have a 3d matrix of dimension $11 \times 1000 \times 3$. I need to remove the first 10 rows from all 2D matrix so that the output is $11 \times 990 \times 3$. After that I need to convert it into a ...
1
vote
2answers
50 views

Find Columns That Match Row Vectors in a Matrix

Suppose I have the following matrix whose row elements are given by the data listed below. ...
1
vote
1answer
85 views

List of lists with non-repeating elements

I have the following lists: l1 = {{a,b},{a,c},{a,d},{a,e},{a,f}}; l2 = {{b,c},{b,d},{b,e},{b,f}}; l3 = {{c,d},{c,e},{c,f}}; l4 = {{d,e},{d,f}}; l5 = {e,f}; I want ...
0
votes
1answer
65 views

Deleting all elements in a list where the output of elements from a function is zero

I tried using DeleteCases to delete elements in r1 where g2==0 to get a defined arithmetic ...
3
votes
0answers
63 views

How to convert list to cycles? [closed]

My code below returns the list: {1, 3, 2, 4}. I want the disjoint cycle representation of this permutation. In other words, I want: ...
2
votes
1answer
69 views

Boundaries problem with listdensityplot

I have to following list to plot (from FEM software) {coord xi, coord yi, speed (norm of) vi} : ...
0
votes
5answers
152 views

How to convert $a(x-p)^2+q$ to $a(x-\alpha+i\beta)(x-\alpha-i\beta)$ for any real $a$, $p$ and $q$ [duplicate]

I want to factorize any quadratic expressions into two complex-valued linear expressions. My effort below ...
2
votes
2answers
216 views

'gradient' function in MMA

How to calculate Numerical gradient of 2D arrays using the "gradient function" ("Matlab-like")? "[___] = gradient(F,hx,hy,...,hN) specifies N spacing parameters for the ...
2
votes
1answer
92 views

Map Function with Table on each row

I need help as I am new to Mathematica. I have a table with some nominal bond values: ...
3
votes
4answers
149 views

Duplicate each element sublist

I have a list of the form {{0,0},{0,1},{1,0},{1,1}} and I want to duplicate each of its elements, i.e. ...
0
votes
0answers
137 views

How can I speed up this pdf path integration calculation with a slow recursive function with 40^4 summed terms in each iteration?

I am writing a path integration code for a numerical approximation to a probability density function. I essentially take some initial continuous probability density function p0 and then perform a ...
1
vote
0answers
59 views
0
votes
2answers
71 views

Unexpected behavior when adding UnitVector to vector (list)

The expression {v1,v2} + UnitVector[2,x] evaluates to {v1 + UnitVector[2, x], v2 + UnitVector[2, x]} but that is suddenly a ...
0
votes
1answer
63 views

Periodic PaddingLayer

The possible values to specify the Padding option of a PaddingLayer include a fixed value, ...
13
votes
2answers
468 views

GroupBy sometimes deletes values

GroupBy[{1, 1, 1, 1, 1, 1}, # > RandomReal[{0, 2}] &] sometimes returns something like ...
18
votes
3answers
509 views

Mathematica 12.x: Don't use Accumulate or Differences on Around objects!

Bug introduced in 12.0 or earlier and persisting through 12.2 or later It seems we've discovered a bug! The following is a summary of the problem and possible workarounds. Scroll down to ORIGINAL ...
1
vote
0answers
68 views

How does this FromDigit module work?

I am entering the following input: ...
2
votes
1answer
88 views

Weighted partitions of a matrix

***Made an important edit to make the "partition" part of the question more clear Let $m,n$ be positive integers. Denote $\left[ m\right] \equiv \{ 1,\ldots ,m\}$. Let $$\mathbf{w} \equiv \...
4
votes
1answer
82 views

Replacing Head of Expression with Table but the variable inside the expression cannot Increment

What is wrong and why I cannot get z = 0; Apply[Table, {z++, {i, 0, 9}}] to output exactly like z = 0; Table[z++, {i, 0, 9}]?
0
votes
0answers
39 views

Non-linear correlation

This may be a more mathematics question. There is also a coding issue. I would like to test non-linear correlation of two vectors Maybe I have overlooked a function that already does this, although my ...
0
votes
0answers
59 views

Calculating my code for higher values of `k`?

How do I calculate the mean of A for higher values of k ...
0
votes
1answer
45 views

Code Producing Power::Infty

I tried computing the following ...
3
votes
1answer
63 views

How to Map over a BlankSequence? [closed]

I would like to replace any function f[x, y, ...] in a certain expression with the same function with all its arguments squared, i.e. ...
2
votes
1answer
82 views

Symmetric matrix from a vector

There is a function VectorToSymmetricMatrix that does the following: ...
4
votes
1answer
115 views

High-water marks of a sequence

I need to write a function that is, given a sequence of integers, extracts the subsequence of its high-water marks (i.e. distinct values of its running maximum). Here are some naïve implementations ...
3
votes
1answer
241 views

Formatting Imported Complex Arrays from Python (csv. files)

Just a short question, I am trying to import a complex array (matrix) from Python to Mathematica by first writing to a csv. file. When I Import the csv. array to Mathematica it is in a form (matrix ...
4
votes
2answers
132 views

Generate permutations partitioned by rotational equivalence

This seems like a very inefficient way of doing what I want. I generate all permutations of (for example) {1, 1, 2, 2}, then for each permutation I generate its ...
12
votes
1answer
305 views

Most efficient way to shift arrays

I would like to know what would be the most efficient way to shift numerical 2D arrays along its dimensions as follows: (A = Partition[Range[9], 3])//TableForm $$\...
5
votes
2answers
123 views
1
vote
1answer
50 views

Why if I change the function Sine to discrete Sine the plot is difference

I would like to know why when I change +1 in a discrete Sine change the list line plot and when I plot the function sine anything change. ...
2
votes
1answer
82 views

restructure a list with brackets

I work with the following list data = {{a}, {{a, b}, {a, b}}, {{{a, b, c}}}}; In real, the dataset is much longer and each row has a different structure of having {...
1
vote
0answers
31 views

Question about a restricted rewrite rule [closed]

I just started learning Mathematica and I'm not sure why a function I defined doesn't work. So I'm trying to write a function that takes a list of vectors and eliminates all zero vectors (with respect ...
2
votes
0answers
37 views

Replace part of list by applying operation to it [closed]

I want to replace, say, list[[i]] by f@list[[i]]. I can use ReplacePart as below, but I ...
0
votes
1answer
85 views

Unable to operate on the table imported from .mx file

I saved a table by exporting it to .mx file. Now, when I import it back, it gives me the desired output. So, to work with elements of the table, I first define the imported table as (...
3
votes
2answers
543 views

How to generate all possible functions combinations

Assume that I have 3 functions like this (total 10 functions in reality). f1[x_] := 3 x; f2[x_] := x^2 - 1; f3[x_] := 2 x + 5; Now I want to generate all possible ...
5
votes
2answers
206 views

List manipulation: all possible sublists

Say I have the following list {a,{b,c},{d,f,g},e} what is the fastest way to get the result lists ...
2
votes
1answer
92 views

Why does this DeleteCases not work? [duplicate]

I believe this is simple but I couldn't figure out why this doesn't work. Everything looks good to me. ...
1
vote
1answer
61 views

Palindrome by deleting a character

I need to find a list of strings with input string length n for whom are palindrome by deleting a character from it . The strings are stored inside function ...
1
vote
0answers
65 views

How to compare and subtract elements in nested list to generate a new list [closed]

I have list of lists like this one: list={{1, 9, 4, 7, 2}, {1, 4, 7, 1, 8}, {0, 5, 7, 2, 9}} where every nested list have 5 elements. I want to compare the third, ...
9
votes
5answers
498 views

How to construct a tree from a preorder traversal

The list t1 = {1, 2, 3, 3, 4, 4, 3, 3, 4, 3, 3, 2, 3, 4, 2, 3, 2}; might be derived from a pre-order traversal of ...