as I'm well aware, using AppendTo for large lists isn't recommended as the function gets progressively slower with each appending done.
Lots of suggestions talk about using Reap and Sow, however the ones I found don't deal with nested lists. My question is relatively simple, how to substitute AppendTo with Reap, Sow as directly as possible?
Specific information regarding my problem: I would like to append data in form of
data = {{x}, {y}}
to a list, so after a few iterations, the list would look something like
list = {{{x1}, {y1}}, {{x2}, {y2}}, {{x3}, {y3}}}
My solution works for only 1 iteration, and then breaks apart because of increasing use of Flatten, so it's obviously a non-working solution. Of course, I'm open to other alternatives, faster than AppendTo.
ThreadorTransposeto shape the separate x and y lists into the shape you want. Look at the second argument toSow– Jason B. May 07 '16 at 09:53{x,y}, what is the problem withReap/Sowhere? If you dolist = Reap[ Do[ Sow[ {x[i], y[i]} ], {i,3} ] ][[2,1]]you get what you want, noFlattening needed. If you generatexandyseparately, see @JasonB's comment. – Marius Ladegård Meyer May 07 '16 at 09:55Internal`Bagdescribed by Daniel Lichtblau in this answer. Look also at this thread for further discussion. – Alexey Popkov May 07 '16 at 10:52