Questions tagged [list-manipulation]

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

299 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
16
votes
0answers
356 views

Strategies to find curves on messy data using FindCurvePath

I have a set of data points that correspond to roots of a transcendental equation with respect to a parameter (the abscissa) which, by the properties of the system, define continuous curves (might be ...
12
votes
0answers
111 views

What changed in String handling between 11.0 and 11.3?

I was trying to optimize some String-handling code here using my standard trick of converting it to a list of bytes first and using basic list operations instead of ...
10
votes
0answers
72 views

Different timing with large array assignment

Consider the following example n = 10^8; AbsoluteTiming[ A = ConstantArray[1., n]; // anyFunc; A[[2 ;; ;; 2]] = -1.; ] {0.388108, Null} ...
9
votes
0answers
96 views

Predicting Pick performance

I'm trying to figure out how to use Pick most efficiently. I use it already in a number of places, but only ever in the context of ...
8
votes
0answers
148 views

About efficiency of modifying large list in place

In Wagner's book "Power Programming with Mathematica" page 303. Wagner metioned do not "modify large list in place" He take two example ...
6
votes
0answers
72 views

Why can't (partially) packed arrays be used in this example?

Bug introduced in 11.3 or earlier and persisting through 12.0 or later I didn't expect any difference between these: ...
6
votes
0answers
253 views

How to create a prefix code

I am trying to create a demonstration of shannon code in mathematica. Given a list of lengths (l1, l2,..lk) I need to create a list of binary lists (or list of ...
5
votes
0answers
91 views

Graph problem with IGraphM package

Consider the graph: ...
5
votes
0answers
74 views

Join on QuantityArray

I need to merge two QuantityArray objects of mixed type. My first attempt looks something like: ...
5
votes
0answers
86 views

SimilarityRules for SequenceAlignment of two lists

I am trying to use the SimilarityRules option of SequenceAlignment to customize its output. This works perfectly for strings, ...
4
votes
0answers
85 views

Graph Partition

Consider a graph 'g': ...
4
votes
0answers
77 views

Why does Shortest not work inside SequencePosition?

Why does Shortest not work in a SequencePosition call? The following two commands return the same answer: ...
4
votes
0answers
239 views

Extract a key from an Association?

I have some large nested expression containing associations and I'd like to extract the nth key inside one of them, using part syntax. Here's a tiny example: ...
4
votes
0answers
88 views

`Optional` with non-empty list requires PatternTest/Condition?

Arbitrary lists are easy to use with Optional: a[0]~MatchQ~a[0, Optional[x_List, {}]] a[0]~MatchQ~a[0, Optional[x:{___}, {}]] ...
4
votes
0answers
91 views

Create an adequate 'training set' to train a ClassifierFunction which performs the role of the built-in `SubsetQ`

I am trying to "grow" my own SubsetQ function using Machine Learning methods. My cSubsetQ when given two lists (listA and listB)...
4
votes
0answers
190 views

Bug in ListLinePlot[] when Filling up and down?

Bug introduced in 9.0 or earlier and persisting through 11.0.1 or later I'm trying to understand this apparently incorrect Filling behavior in ...
4
votes
0answers
173 views

ParallelTable and expensive functions

I would like to build up a 2D-Table using ParallelTable as follows ...
4
votes
0answers
168 views

Gather dependency on list order?

I get intrigued about Gather behavior on this post. I thought that Gather was invariant under list order? Here is the result I ...
3
votes
0answers
30 views

Fastest way to change the values of an association

I have an association of the following form : assoc = Association[a -> {1, 2, 3}, b -> {5, 6, 7}] <|a -> {1, 2, 3}, b -> {5, 6, 7}|> (the size ...
3
votes
0answers
40 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 ...
3
votes
0answers
42 views

Bags don't work in parallel code?

Appending to a list in parallel works: b = {}; SetSharedVariable[b] WaitAll[Table[ParallelSubmit[{p}, AppendTo[b, 1]], {p, 3}]]; (* b is now {1,1,1} *) But ...
3
votes
0answers
56 views

Net layer that replicates last element

I am trying to design a neural network layer that takes in an array of dimensions n x 100, and produces an array of dimensions ...
3
votes
0answers
54 views

Speeding up MovingMap of Dot

I have the following code (showing an insignificant simplification) that I really need to run many times for different ps (its length can be 10^7 or so) and wSize. Is there a way to speed this up ...
3
votes
0answers
152 views

`Transpose` nested `Association`

Say I have a nested Association like this one: ...
3
votes
0answers
71 views

Strange behaviour with Differences

I have some problems with the built-in function Differences. I do not understand how its behaviour comes about under the following circumstances: ...
3
votes
0answers
564 views

Multiple variable assignment from a list

For example in Python, if we have a list of 3 elements, say ls = [1,2,3] and we want to assign a variable to each value (from left to right), one can do as follows: ...
3
votes
0answers
1k views

Is it possible to reshape with one unknown dimension in Wolfram?

In Python I can reshape array remaining one dimension unknown, allowing Python to infer it automatically: ...
3
votes
0answers
174 views

Finding possible lattice planes of a crystal structure

After generating a crystal structure from a crystallographic data and duplicating it to a larger crystal system I would like to find possible lattice planes of this crystal. It is well-known that the ...
3
votes
0answers
70 views

Can a simple Part expression produce a list of elements from nested lists?

If list1d is a simple 1-d list, then list1d[[{i, j, k}]] evaluates to a list consisting of the ...
3
votes
0answers
53 views

Applying a function along the desired dimensions of a n-dimensional array

I am trying to apply an arbitrary function f that takes several inputs and returns a scalar along some specific dimensions of an n-dimensionnal array. Here is an ...
3
votes
0answers
72 views

Incrementally building a list without memory overhead

I have a task, where I have to combine pairs with a function, but the number of pairs I actually need is much smaller than the number of all pairs. The condition to keep the element is some function ...
3
votes
0answers
56 views

Test which symbol of a list depend on some variable

Given a list of symbols, say {y[x],z[x],k} Is there a way to sort which depend on x and which don't ? Applied to the above list,...
3
votes
0answers
54 views

Map entries of StructuredArray

I have the following defintion arr = SymmetrizedArray[{1, 2} -> 1, {4, 4}, Antisymmetric[{1, 2}]] which gives a ...
3
votes
0answers
97 views

How to make reading from long lists faster?

Background I am using Mathematica to solve a traveling-salesman-like problem. I implemented two different algorithms that are able to solve this type of problem and both algorithms yield the same ...
3
votes
0answers
90 views

How to ArrayFlatten some matrix which have repeated element

I have many such matrices(whose dimension are all 3*3.) like: ...
3
votes
0answers
100 views

How to deal with “Compile::cset” in Compile

When compiling below code Compile[{{data, _Integer, 2}}, Fold[Flatten /@ Flatten[Outer[List, ##, 1], 1] &, data]] I encountered error messages Compile::...
3
votes
0answers
97 views

Mysterious Riffle::rspec warning

I have part of a code that looks like this: ...
3
votes
0answers
686 views

Taking real and imaginary parts of indexed functions and speeding up ComplexExpand

I am setting up a large system of ODEs and in order to use the IDA method (which is sig. faster for my system and thus attractive), I must split my equations into real and imaginary parts. I am ...
2
votes
0answers
80 views

Using Fold[ or Map[ Better?

I'm working through MMA Cookbook by Mangano, page 54. He shows Map is a compact form of Fold function. Is using ...
2
votes
0answers
46 views

SortBy without final cannonical ordering

How can I SortBy a list without final cannonical ordering? E.g. SortBy[{9, 1, 2, 5, 3, 7}, # Boole[# >= 6] & ] returns <...
2
votes
0answers
68 views

How to use a List in Do-loop?

My program produces a list that looks exactly like this: listr = {{i[1], 0, 13}, {i[2], 0, 21}, {i[3], 0, 41}, {i[4], 0, 5}}; Now I want to use this list in a <...
2
votes
0answers
109 views

Calculate the intersection points of a line and a parametrically defined 3D surface

Thanks to Henrik Schumacher for advice to simplify the sample code: I would be grateful for any pointers on the following issue. A line from an external point intersects the surface at 2 points (...
2
votes
0answers
38 views

When mapping FindMinimum to a list, how to find out which instance does not converge

I defined a function f[x,y] and wanted to study its minimum over x when viewing y as a ...
2
votes
0answers
38 views

Error with combining lists

I'm attempting to combine lists of the form ...
2
votes
0answers
51 views

How to calculate a projection of x,y,z data to x any y plane?

I have a List containing x,y,z data, which I can plot nicely in a ListContourPlot: ...
2
votes
0answers
81 views

ListDensityPlot using

I have two data tables with identical parts along the vertical axis. For example: ...
2
votes
0answers
73 views

Converting video file to list of images to analyze pixels of each frame

I am trying to recreate the following physics experiment to analyze chaotic motion: https://www.researchgate.net/publication/275890532_Tracking_the_Motion_of_a_Double_Pendulum_Using_Mathematica I ...
2
votes
0answers
58 views

Fold/ NestList/ etc in MCMC loop for optimisation

I am trying to simplify and optimise an old loop code I wrote. Since Fold and NestWhile use the results of the last iteration in the new iteration, I would like to use them in order to get rid of Do ...
2
votes
0answers
32 views

Partition data but dropping elements between each sublist

Is there a neat way to partition a list into sublists of fixed length $n$, discarding a fixed number $k$ elements between each one? E.g for $n=3, k=1$, ...
2
votes
0answers
82 views

Run function as loop over two matrices

I'm still wrapping my head around Mathematica syntax. I have a matrix clustersAll that looks like ...

1
2 3 4 5 6