I'm running some analysis that requires the creation, row by row, of a large list of lists. The big list is called "Nodes" and it will ultimately contain hundreds of thousands of rows. The first few rows will look like this ...
Row 1: {{1,3,5}, {2,4,6}, {7}, {6,7,8,9}}
Row 2: {{7,3,8}, {2,5,4}, {2}, {6,2,8,4}}
Row 3: {{9,7,5}, {5,4,6}, {1}, {6,7,8,9}}
I've tried AppendTo and Join in this way ...
Nodes = AppendTo[Nodes,List[{8,3,2},{1,2,3},{8},{8,3,3,2}]];
Nodes = Join[Nodes,List[{8,3,2},{1,2,3},{8},{8,3,3,2}]];
and they both take quite a long time to run.
I also tried creating a huge Nodes array ahead of time and then replacing each row, something like this ...
Nodes = Range[200000];
For[ji = 1, ji < 200001, ji++, Nodes[[ji]] = List[{}, {}, {}, {}]];
followed by
Nodes[[nodesrownumber]] = List[{8,3,2},{1,2,3},{8},{8,3,3,2}]];
and this seems to take even longer.
Any suggestions for improving the speed of this? Thanks, very much, in advance.
AppendTo
. In any case, where do the elements come from? Are you generating them randomly, from prior results in list, from some other list, from... you need to specify this question much more precisely. $\endgroup$AppendTo
Is probably your problem because it generates a copy of its argument before appending. Look into using e.g.Reap
andSow
instead (blog.wolfram.com/2011/12/07/… and mathematica.stackexchange.com/questions/70149/…). We will also need to know how you are generating your lists in order to help you. $\endgroup$