Questions tagged [list-manipulation]

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

545 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
18 votes
0 answers
425 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 ...
Pragabhava's user avatar
  • 1,599
12 votes
0 answers
126 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 ...
b3m2a1's user avatar
  • 46.6k
10 votes
0 answers
287 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 ...
Teabelly's user avatar
  • 984
10 votes
0 answers
83 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} ...
matrix42's user avatar
  • 6,744
9 votes
0 answers
110 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 ...
b3m2a1's user avatar
  • 46.6k
8 votes
0 answers
166 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 ...
matheorem's user avatar
  • 16.9k
7 votes
0 answers
252 views

Bug in ListLinePlot[] when Filling up and down?

Bug introduced in 9.0 or earlier and persisting through 13.2.0 or later I'm trying to understand this apparently incorrect Filling behavior in ...
Jess Riedel's user avatar
  • 1,506
6 votes
0 answers
90 views

Join on QuantityArray

I need to merge two QuantityArray objects of mixed type. My first attempt looks something like: ...
b3m2a1's user avatar
  • 46.6k
5 votes
0 answers
99 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: ...
Roman's user avatar
  • 44.9k
5 votes
0 answers
112 views

Graph problem with IGraphM package

Consider the graph: ...
ralph's user avatar
  • 1,019
5 votes
0 answers
2k views

Speed differences between Table, Replace, Array, Map, and AssociationMap

EDIT: Actually, it looks like part of this is bogus—Array doesn't actually work on this input (I'm often a little shaky on what kind of input, exactly, works for ...
Ben Kalziqi's user avatar
  • 1,072
5 votes
0 answers
106 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, ...
Thijs's user avatar
  • 680
5 votes
0 answers
779 views

How to extract structured array data from DefineDLLFunction in Mathematica

I want to use my Bluechip PCI-ADC acquisition card in Mathematica via his dynamic link library “Bcdll32.dll”; (used to access functions on my PCI data acquisition cards). My problem is the function “...
rosu_constantin's user avatar
4 votes
2 answers
189 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? ...
1729taxi's user avatar
  • 737
4 votes
0 answers
165 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-...
Just Some Old Man's user avatar
4 votes
0 answers
102 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 ...
DarkBulle's user avatar
  • 964
4 votes
0 answers
164 views

Graph Partition

Consider a graph 'g': ...
ralph's user avatar
  • 1,019
4 votes
0 answers
68 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 ...
freevillage's user avatar
4 votes
0 answers
315 views

`Transpose` nested `Association`

Say I have a nested Association like this one: ...
sunt05's user avatar
  • 4,317
4 votes
0 answers
376 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: ...
M.R.'s user avatar
  • 31k
4 votes
0 answers
201 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 ...
Julian's user avatar
  • 131
4 votes
0 answers
130 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::...
matheorem's user avatar
  • 16.9k
4 votes
0 answers
120 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:{___}, {}]] ...
masterxilo's user avatar
  • 5,679
4 votes
0 answers
105 views

Why isn't SparseArray working in this case?

This works: SparseArray[{{1, 1} -> 1, {2, 2} -> 2}]\ (* {{1, 0}, {0, 2}} *) This works: ...
user170231's user avatar
  • 1,581
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)...
conor's user avatar
  • 7,349
4 votes
0 answers
189 views

ParallelTable and expensive functions

I would like to build up a 2D-Table using ParallelTable as follows ...
jibe's user avatar
  • 841
4 votes
0 answers
192 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 ...
Murta's user avatar
  • 26k
3 votes
0 answers
57 views

Operating on a nested list

A very short version of my list named "fire" is fire = {{0, 0, 0, 20, 0, 0}, {0, 0, 0, 20, 0, 0}, {0, 0, 20, 20, 0, 0}}. For the first sublist ...
RUG's user avatar
  • 31
3 votes
0 answers
74 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: ...
S.B.MD.Khaja Moinuddin's user avatar
3 votes
0 answers
87 views

Transpose[m,{1,1}]

According to the documentation, Transpose with a second argument {1,1} on a square matrix returns the diagonal of the matrix. ...
Whelp's user avatar
  • 1,685
3 votes
0 answers
107 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 ...
Just Some Old Man's user avatar
3 votes
0 answers
53 views

Why is doing a computation inside Select slower than a precomputation?

I am trying to generate primitive Pythogorean triples using Euclid's parametrization. I basically want a list of pairs with ordered pairs $(m,n)$ such that $m$ and $n$ are coprime. My first approach ...
Fixed Point's user avatar
3 votes
0 answers
75 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: ...
flinty's user avatar
  • 23.1k
3 votes
0 answers
56 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 ...
M.R.'s user avatar
  • 31k
3 votes
0 answers
63 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 ...
Nico A's user avatar
  • 3,604
3 votes
0 answers
87 views

How can I prevent ParallelTable[] from freezing?

I have spent some time trying to figure this out. I have a function that appears to be the reason my program is freezing. I am using both MemoryConstrained[] and <...
Jmeeks29ig's user avatar
  • 1,407
3 votes
0 answers
73 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: ...
NeverMind's user avatar
  • 1,201
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: ...
Dims's user avatar
  • 735
3 votes
0 answers
274 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 ...
PhilG's user avatar
  • 31
3 votes
0 answers
74 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 ...
kjo's user avatar
  • 11.7k
3 votes
0 answers
106 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 ...
Mary's user avatar
  • 31
3 votes
0 answers
80 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 ...
orion's user avatar
  • 141
3 votes
0 answers
63 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,...
jrekier's user avatar
  • 453
3 votes
0 answers
60 views

Map entries of StructuredArray

I have the following defintion arr = SymmetrizedArray[{1, 2} -> 1, {4, 4}, Antisymmetric[{1, 2}]] which gives a ...
Stan's user avatar
  • 941
3 votes
0 answers
108 views

How to ArrayFlatten some matrix which have repeated element

I have many such matrices(whose dimension are all 3*3.) like: ...
yode's user avatar
  • 26.1k
3 votes
0 answers
56 views

How does ContourDetect work for arrays?

By the Wolfram Documentation, ContourDetect gives a binary sparse array in which 1 corresponds to zeros and zero crossings in an array. However, in the example: ...
amasics's user avatar
  • 249
3 votes
0 answers
103 views

Mysterious Riffle::rspec warning

I have part of a code that looks like this: ...
Taiki's user avatar
  • 5,189
3 votes
0 answers
76 views

How to specify alignment of columns when exporting a table using Export, and how to use spaces instead of tabs?

I have a table in list representation. How can I export it, specifying that some columns must be right-aligned and others left-aligned? Morevoer, columns should be space-separated (with an appropriate ...
a06e's user avatar
  • 11.1k
3 votes
0 answers
96 views

Choosing a List as VertexWeight for a TreeGraph

I would like to map every vertex of my TreeGraph to an List. ...
Florian-kun's user avatar
3 votes
0 answers
697 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 ...
Nick P's user avatar
  • 349

1
2 3 4 5
11