# Questions tagged [list-manipulation]

Questions on the manipulation of List objects in Mathematica, and the functions used for these manipulations.

8,816 questions
Filter by
Sorted by
Tagged with
47 views

### Plotting Individual Variables from RandomFunction

I have defined an Ito Process such that: ...
• 419
75 views

### Table range as disconnected interval

I wish to evaluate table entries but with the dummy variable taking values in separate intervals. For instance, instead of writing ...
1 vote
59 views

### Efficiency on array iteration

Consider a 2-d array n by n of the form array1 ={ {x11,x12,x13,...,x1n},{x21,x22,x23,...,x2n},{xn1,xn2,xn3,...,xnn}}. I want to expand every point in this array in ...
88 views

### Minimize Sum of Hamming Distances

Problem: Given an $n \times m$ matrix with binary values $(0,1)$, find a binary vector that minimizes the sum of Hamming Distances to the rows. Example: If the matrix is {{$1,1,1$},{$0,0,0$},{$1,0,1$}}...
• 35
89 views

### Finding the consecutive distance of n-dimensional points with Mathematica

I want to create a list of (n-dimension, average of points) with 10,000 points per n-dimension. I can't figure out how to take the distance of consecutive points. Say in 2-dimensions, there are 3 ...
• 31
1 vote
107 views

### How to generate a numerical table?

I have the following issue for generating a table in Mathematica. How to generate a table with the limits 10^-18 to 10^-6 with steps of (1,2,3, ....10)*10^-1? e.g. It should look of the following form:...
• 125
111 views

### Get the coordinates from RegionPlot3D

I have a plot generated with RegionPlot3D and need to extract the coordinates of the points on the plot. I'm trying to apply the approach from this question about RegionPlot to RegionPlot3D but it ...
• 133
48 views

### Droping a row from a matrix [duplicate]

I want to drop a row from a matrix but the output seems to be: MatrixForm[] My code: ...
836 views

### Implementation of MATLAB's "numgrid" function [closed]

I am looking for an implementation of MATLAB's numgrid function, in particular the "B" mode. For example, I want to get the matrix corresponding to the ...
• 6,441
69 views

### Sorting of a list of lists - i.e. list of matrices - what is the order of the sort determined by?

In the documentation we have: Sort[list] sorts the elements of list into canonical order. Maybe I am missing something but what does "canonical order" mean for sorting a list of matrices? ...
• 525
163 views

### How to map a function across multiple ragged lists

Preliminaries I have lists that are lists of lists (i.e., each list contains one or more sublists and are ragged (i.e., each sublist can have a different length, though all have a length of 1 or ...
• 9,505
211 views

### matrix Crop (remove leading and trailing zeroes in matrix)

I have some matrices that have 0's around them, for example, give such a matrix MatrixForm[ mat = ArrayPad[{{1, 2, 3}, {0, 0, 0}, {7, 8, 0}}, {{1, 2}, {2, 3}}]] \...
• 4,994
1 vote
88 views

### How to assign table parameters to use it many times

I'm using two nested Table to generate data which depend on two parameters, let's say it is temperature and pressure, many times in my code. When I change the temp ...
• 95
174 views

### Generating a non-convex polyhedron from polygons and normals

I am working on developing "directional offset" module, which requires pretty tricky mesh generation: offset values vary in different directions. Suppose I have list of points and polygons, ...
• 303
1 vote
62 views

### Draw the values of two variables each on a axis in a square

I plot lists of {xA1} over time and lists of {yB1} over time. Now, How can I draw two lists {xA1} and {yB1} so that the values of each are shown on a separate axis inside a square? (same as below ...
• 77
64 views

### Pulling Results from NDSolve within a Table

I am still learning the intricacies of Mathematica. I have an NDSolve within which I am trying to vary a specific parameter (I understand that ParameticNDSolve is likely a more efficient tool--the ...
• 31
29 views

### DiscretePlot with a List as argument [duplicate]

Suppose I have some multidimensional function that is computationally very expensive to evaluate. Here, I will just use ...
• 101
39 views

### How to replace the 6th column with another column? [duplicate]

Consider the following table: tabb = Table[RandomReal[{0, 100}, 100], {i, 1, 10, 1}]; How to replace its kth column (say, the 52th column) by the column ...
• 4,116
143 views

### Add quotes to each element in a list

How to add quotes to each element in a list? For example, we have a list as: ...
• 513
1 vote
57 views

### An error in the short form of a two-dimensional array?

I noticed very strange behavior in the function Short when applied to a two-dimensional list of real numbers in Mathematica 12.3. Consider that ...
• 101
79 views

### Plot two list for differen first list parameter

I have a series of equations based on which I plot final lists of "xA1","yB1". I need to change "xA1 = {0.55}" and "yB1 = {0.6}" between [0,1] with interval 0....
• 77
158 views

### Find first position satisfying condition, which is true after a certain element

Can we find the first position of elements of a list satisfying a condition, with good performance, if the conditions is a tail condition of the list. What is tail condition ? (the term is informal, ...
• 3,221
64 views

### Why the performance of list of Timings depend on the order?

It seems that the result of list of Timings and AbsoluteTimings depends on the order, while ...
• 643
449 views

### How can I create an atomic head or treat some head as atomic during Map?

For example, Map[g, {0, {h[1, 2, 3]}}, {-1}] gives {g, {h[g, g, g]}} I want a ...
• 16.4k
56 views

### Multiple columns from a single column of data file

Suppose I have a data file containing one column of 1000 rows having x, y, z and ϕ values. I need to separate them into four distinct columns by selecting every alternative value. For example, if I ...
• 664
1 vote
52 views

### How to select in the following way?

Consider the following nested list: fff = {{1, 2, {{1, 2}, {3, 4}, {19, 20}, {21, 22}}}, {2, 8, {{0.5, 3}, {1.4, 2}, {3, 13}, {2, 18}, {0.3, 19}, {20, 21}}}} ...
• 4,116
453 views

### How to replace anti diagonal elements of a matrix

I want to assign new values to the anti-diagonal elements of a square matrix m with the values of its diagonal elements. For that, I want to make use of ...
• 319
145 views

### Help understanding a bug when FoldList using RandomChoice is Compiled

Bug introduced in 3.0, persisting through 13.1. Preamble: I submitted this bug to support@wolfram.com and it was acknowledged. I assume it will be fixed eventually. In the meantime I'd like to ...
• 1,549
1 vote
98 views

### Convert List to Matrix [closed]

I have the lists in matrix form, as shown in the screenshot fig.2 below. I would like to convert it to pure matrix like fig.1 Edited: For example: ...
• 143
1 vote
57 views

### How to efficiently rearrange elements in big data file? [closed]

I have this data and would like to rearrange the element in a specific way, I used Table but it tasks time 12 sec, is this ...
• 3,517
83 views

### Selecting terms from a list based on certain pattern

I have the following table: ...
• 357
1 vote
65 views

### Table mix with If function [closed]

Anyone could explain to me which problem is? after running the function "Table" combining with "If" as below, but the result is not a value instead. ...
• 143
1 vote
184 views

### Generating Lyndon words modulo mirroring operation and substituion

I have two letters A,B. I want to generate all words say up to length 22 with the following properties. There is no "canonical" list so any such list will suffice, though there are many ...
• 635
1 vote
77 views

### 2D Scatter plot with z-value used for PlotLegends

I have a data set that can be generated as follows: x=RandomReal[{1,5},100]; y=RandomReal[{11,50},100]; z=RandomReal[{7,25},100]; For each of the (x,y,z) 3-tuple, ...
• 107
110 views

### Write the result of expression to a list [closed]

I have a question. I want to write the result of the expression such as y=2cos(n.Pi/3) for 100 values n into a list. Could you tell me which code I should use?
• 143
113 views

### Unexpected behaviour of Condition with Cases/MatchQ?

When using the unsorted version of Complement in this question I met the following unexpected result, ...
• 643
141 views

### Divide string into a sublist of sentence with the maximum number of character

Context: I have a long article (on Wordpress). And I'm using Google Translate API (v2) to translate this article. This article has about 300 000 characters. However, due to the limit of Google ...
• 1,701
44 views

### Timing Discontinuity with Replace[] Function

When constructing certain square matrices I noticed a sharp jump in the time required to build them. I've included code and a plot of time required to make the matrix vs dimensionality of the matrix. ...
• 187
581 views

### Replacing large numbers

Imagine I have the following list l = {{1,2,3},{4,10^(16),5}} How do I efficiently replace the large number by a number (zero, for example). I can't seem to do it ...
• 4,388
358 views

### How to generate a list of random numbers with conditional statements

I want to generate a list of numbers with certain conditions. Eg. First I generated 10 random numbers between 1 and 20. M1= RandomReal[{1,20},10] Now I want to ...
• 107
656 views

### What is the best method to search pattern for 2D list?

What is the best method to search patterns for 2D list ? Let L be following 2D-list : ...
• 3,221
313 views

### Simple, fast re-defining a part of 2D list

A[[{2, 3, 5}]] = {97,98,99} changes 2,3,5-th elements of A to 97,98,99 respectively. Similary A[[{2, 3, 5}]] = 100 changes 2,3,...
• 3,221
54 views

### Piecewise Functions from List of Functions

I have multiple functions from two different NDSolves that I would piece together. Here is a working minimal example: ...
1 vote
66 views

### Why does my simple string function fail to grab the only element in a List?

The idea is to normalize a string before processing it to extract information from it. Strings may come with embedded outer brackets which are easily stripped or as elements of a true list. This is ...
• 1,977
98 views

### Loop over multiple variables with readable code

I've seen similar posts to this, but not with as many variables. I need to loop over 8 variables, with only two values each(1 and 2), so I can loop over the 16 possible input and output states, and ...
647 views

### How can I multiply only a few columns of a table by some number in a compact way?

Consider a table tab = Table[{i,i^2,i^3,i^5,i^0.3,i^0.7},{i,0.2,3,0.1}]; I would like to multiply the 2rd and 5rd columns by some number. This is how I do it: <...
• 4,116
39 views

### Generalised KroneckerProduct that works like Outer[] [closed]

Is there a Mathematica function that works like this: Function[f, A, B] where f is a function with two arguments, and ...
• 103
108 views

### Parsing an expression for coefficients and more

I have many expressions of this form: ...
• 141
111 views

### Doing ArrayReshape in Mathematica doesn't give desired results

I have an array like this for example, a = ArrayReshape[Range, {4, 4}] \begin{align} \left( \begin{array}{cccc} 1 & 2 & 3 & 4 \\ 5 & 6 & ...
• 519
1 vote