Questions tagged [list-manipulation]

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

419 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
17 votes
0 answers
408 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 ...
user avatar
  • 1,579
12 votes
0 answers
120 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 ...
user avatar
  • 45.4k
10 votes
0 answers
258 views

Visualising 'The Moessner Miracle' in higher dimensions

I thought it would be interesting to try and represent "The Moessner Miracle" in higher dimensions. This is my first attempt for higher dimensions anywhere so I'm not sure if the logic is ...
user avatar
  • 974
10 votes
0 answers
77 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} ...
user avatar
  • 6,510
9 votes
0 answers
103 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 ...
user avatar
  • 45.4k
8 votes
0 answers
161 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 ...
user avatar
  • 15.6k
6 votes
0 answers
260 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 ...
user avatar
  • 205
6 votes
0 answers
224 views

Bug in ListLinePlot[] when Filling up and down?

Bug introduced in 9.0 or earlier and persisting through 13.0.0 or later I'm trying to understand this apparently incorrect Filling behavior in ...
user avatar
  • 1,428
5 votes
0 answers
105 views

Graph problem with IGraphM package

Consider the graph: ...
user avatar
  • 969
5 votes
0 answers
80 views

Join on QuantityArray

I need to merge two QuantityArray objects of mixed type. My first attempt looks something like: ...
user avatar
  • 45.4k
5 votes
0 answers
101 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, ...
user avatar
  • 680
4 votes
0 answers
157 views

Inconsistent Output Bug and Code-Quits-Kernel Bug with Compile

This is the strangest bug I've encountered. In my experience, variations in the code will unexpectedly crash the kernel, give inconsistent output, or produce expected results with no problems. 1) Code-...
user avatar
4 votes
0 answers
69 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 ...
user avatar
  • 912
4 votes
0 answers
137 views

Graph Partition

Consider a graph 'g': ...
user avatar
  • 969
4 votes
0 answers
88 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: ...
user avatar
  • 35.7k
4 votes
0 answers
61 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 ...
user avatar
4 votes
0 answers
261 views

`Transpose` nested `Association`

Say I have a nested Association like this one: ...
user avatar
  • 4,157
4 votes
0 answers
324 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: ...
user avatar
  • 30.3k
4 votes
0 answers
113 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::...
user avatar
  • 15.6k
4 votes
0 answers
104 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:{___}, {}]] ...
user avatar
  • 5,559
4 votes
0 answers
96 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)...
user avatar
4 votes
0 answers
182 views

ParallelTable and expensive functions

I would like to build up a 2D-Table using ParallelTable as follows ...
user avatar
  • 741
4 votes
0 answers
178 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 ...
user avatar
  • 25.3k
3 votes
0 answers
91 views

Filling the space with rectangles

The problem concerns filling the matrix m x n with rectangles. ...
user avatar
  • 969
3 votes
0 answers
68 views

Fastest Way to make rows and columns zero and corresponding (i,i) element 1 of a large Sparse Matrix

I have a 5552 by 5552 sparse matrix: ...
user avatar
3 votes
0 answers
103 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 ...
user avatar
3 votes
0 answers
74 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: ...
user avatar
  • 20.4k
3 votes
0 answers
48 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 ...
user avatar
  • 30.3k
3 votes
0 answers
62 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 ...
user avatar
  • 3,564
3 votes
0 answers
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: ...
user avatar
  • 1,171
3 votes
0 answers
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: ...
user avatar
  • 725
3 votes
0 answers
237 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 ...
user avatar
  • 31
3 votes
0 answers
73 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 ...
user avatar
  • 11.4k
3 votes
0 answers
63 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 ...
user avatar
  • 31
3 votes
0 answers
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 ...
user avatar
  • 141
3 votes
0 answers
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,...
user avatar
  • 443
3 votes
0 answers
59 views

Map entries of StructuredArray

I have the following defintion arr = SymmetrizedArray[{1, 2} -> 1, {4, 4}, Antisymmetric[{1, 2}]] which gives a ...
user avatar
  • 941
3 votes
0 answers
146 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 ...
user avatar
  • 121
3 votes
0 answers
99 views

How to ArrayFlatten some matrix which have repeated element

I have many such matrices(whose dimension are all 3*3.) like: ...
user avatar
  • 23.4k
3 votes
0 answers
99 views

Mysterious Riffle::rspec warning

I have part of a code that looks like this: ...
user avatar
  • 5,059
3 votes
0 answers
693 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 ...
user avatar
  • 349
2 votes
0 answers
39 views

Delete list item if message is thrown

I have a nested list with each element containing FindRoot like this: {FindRoot[a,b], FindRoot[c,d], FindRoot[e,f],...} ...
user avatar
2 votes
0 answers
82 views

How to use Select and MemberQ together with Map correctly?

I have a list with quite a few elements. Each element is a rule of the type vector-> number such as {1,2,3,4}->1.435 and ...
user avatar
2 votes
0 answers
36 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 ...
user avatar
2 votes
1 answer
102 views

Periodic PaddingLayer

The possible values to specify the Padding option of a PaddingLayer include a fixed value, ...
user avatar
2 votes
0 answers
55 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 ...
user avatar
  • 648
2 votes
0 answers
104 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 ...
user avatar
  • 4,006
2 votes
0 answers
46 views

Error using Standardize

I'm trying to standardize a set of data. ...
user avatar
  • 747
2 votes
0 answers
80 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\...
user avatar
  • 199
2 votes
0 answers
49 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 ...
user avatar

1
2 3 4 5
9