Questions tagged [list-manipulation]

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

358 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
17
votes
0answers
387 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
115 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
75 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
99 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
152 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 ...
7
votes
0answers
74 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
257 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
95 views

Graph problem with IGraphM package

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

Join on QuantityArray

I need to merge two QuantityArray objects of mixed type. My first attempt looks something like: ...
5
votes
0answers
95 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
57 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 ...
4
votes
0answers
79 views

What exactly is the difference between Part and Extract?

From the statement in the documentation: Extract[expr,{i,j,…}] is equivalent to Part[expr,i,j,…]. So basically Extract is just a listable version of ...
4
votes
0answers
113 views

Graph Partition

Consider a graph 'g': ...
4
votes
0answers
83 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
60 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 ...
4
votes
0answers
205 views

`Transpose` nested `Association`

Say I have a nested Association like this one: ...
4
votes
0answers
276 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
105 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::...
4
votes
0answers
91 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
95 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
195 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
177 views

ParallelTable and expensive functions

I would like to build up a 2D-Table using ParallelTable as follows ...
4
votes
0answers
177 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
95 views

Sowing Once into Each of Many Lists – Any Better than Append?

In general I know to try to use Reap and Sow over Append or AppendTo due to superior performance. However, Reap and Sow are notorious for being difficult to understand how to use and how they work ...
3
votes
0answers
66 views

Why is ContainsOnly so slow for checking a list is full of zeros?

I'm on Windows 10 Mathematica 12.1.1. I would expect allocating a big ConstantArray and comparing would be slower but apparently it is not: ...
3
votes
0answers
53 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
44 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
60 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
72 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
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
207 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
72 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
56 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
74 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
56 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
111 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
94 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
98 views

Mysterious Riffle::rspec warning

I have part of a code that looks like this: ...
3
votes
0answers
692 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
32 views

Example of when explicitly using MapThread is better than giving a function the Listable Attribute

This answer says that Listable just makes the function automatically apply MapThread to its arguments. Does anyone have a simple ...
2
votes
2answers
105 views

Restrict kinds of heads when dealing with level concept

In[1] Map[(# + 7) &, {a, 3 b, {c, d}, e}, {2}] Out[1] {a, 10 (7 + b), {7 + c, 7 + d}, e} But I want feature like ListMap : ...
2
votes
0answers
48 views

Handling lists indexed with integer partitions

I am trying to do some exploration around the multi-dimensional version of [truncated moment problem], where I work with various distributions (uni- or multi-variate), and use some truncated moment ...
2
votes
0answers
87 views

Repeated calling of a ParametricNDSolve result in a faster way?

I recently learned of ParametricNDSolve and found that I need to compute it once and then call its result sol at different ...
2
votes
0answers
42 views

Error using Standardize

I'm trying to standardize a set of data. ...
2
votes
0answers
76 views

For any countable totally-ordered $A$, how can mathematica show my choice function gives a unique collection of finite sets whose union is $A$?

Suppose $A=\sqrt{\mathbb{Q}}_{>0}$. We want a unique $\bigcup\limits_{i\le j}A_i$ for $i,j\in\mathbb{N}$ such that $A_i$ is finite, $A_i\subseteq A_{i+1}$, and $\lim\limits_{j\to\infty}\bigcup\...
2
votes
0answers
42 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 ...
2
votes
0answers
59 views

How to work around TuringMachine's lack of a halting mechanism

It looks like the TuringMachine function doesn't have a halting mechanism. When I say "halting mechanism", I mean something that's built-in to the ...
2
votes
0answers
41 views

ListContourPlot and ListPlot3D return empty (white) plots when scaled

using Mathematica 11.1.1.0. I could not find this topic before. Look at these simple data plots: ...
2
votes
0answers
88 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 ...

1
2 3 4 5
8