Skip to main content

Questions tagged [sow-reap]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3 votes
7 answers
428 views

Extract result of Reap in a natural way no matter if it's empty

This feature has long troubled me, I would like to share it. If Reap has non-empty set of sown, result looks like: ...
lesobrod's user avatar
  • 1,729
12 votes
0 answers
177 views

How to parallelize Reap and Sow in Mathematica 14.0.0?

I'm working with a huge amount of data, so I'm avoiding using AppendTo. I used to use the Reap and ...
Pedro Croti's user avatar
3 votes
3 answers
279 views

How to effectively guess the initial values for a Poincaré section?

I have the following code, which plots the Poincaré section for the trajectory of particles around a symmetric black hole: ...
codebpr's user avatar
  • 2,423
9 votes
4 answers
473 views

Poincaré section of the particle motion near the black hole horizon

I am trying to recreate the Poincaré sections given in Figure 2 of this paper. For this purpose, I use the following two methods: Method1: Using ResourceFunction["ClickPoincarePlot2D"] <...
codebpr's user avatar
  • 2,423
0 votes
0 answers
41 views

Optimization of conditions applying

Let we have some data generator, e.g. lazy tuples or permutations. I need to select data by some conditions cond1, cond2, …, up to 5-6 conditions. All of them need ...
lesobrod's user avatar
  • 1,729
3 votes
2 answers
527 views

Recreating Poincaré section for a double pendulum

I am trying to recreate the Poincaré Sections for the double pendulum as described in this paper. I am unable to figure out a way to include energy values in the code. The code that I used until now ...
codebpr's user avatar
  • 2,423
0 votes
3 answers
146 views

How do I create a Table from a For loop?

I've been trying to create a table that has the % of the cycle of a sample and the module of acceleration for the first 100 values, but I don't know how to create it. Here's the code: I have imported ...
Pamsh's user avatar
  • 1
5 votes
3 answers
303 views

Join not working

I am trying to append elements to a list in Mathematica using the join function but it is not working. Here is a small working example: ...
Granger Obliviate's user avatar
15 votes
1 answer
328 views

What Reap/Sow tricks do you use?

I admit that I have been reluctant to use Reap and Sow for years and that I used it only when I had no choice with ...
userrandrand's user avatar
  • 5,937
5 votes
1 answer
154 views

Using Reap Sow to define unsorted union [closed]

In the documentation of Reap under "Applications" paragraph there is this example: ...
azerbajdzan's user avatar
  • 19.7k
0 votes
0 answers
41 views

What is the best memory utilization and efficiency considerations for simulating particles that are randomly created and removed?

I am wanting to run a simulation involving a varying number of "particles" (points defined by 2D coordinates $(x,y)$ within some region). At each time step, there is a probability that a new ...
BioPhysicist's user avatar
  • 1,134
3 votes
1 answer
44 views

Keep Reap / Sow results after breaking out of a loop [closed]

I am doing a long calculation where I create a list using Reap and Sow. However, sometimes this calculation gets too wild and I ...
Philipp's user avatar
  • 51
24 votes
2 answers
2k views

What happens if you don't Reap what you've Sown?

As I understand it, when using Sow[expr] you throw the expr on some private stack which you can ...
Gert's user avatar
  • 1,580
4 votes
1 answer
523 views

Bifurcation diagram for Lorenz attractor

As I was following a similar question I came across a beautiful answer here. However, in that code, he used InternalBag[] which heavily depends on ram that I can't ...
user444's user avatar
  • 2,550
3 votes
0 answers
108 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
0 votes
1 answer
39 views

Sow and Reap returning different results for the same expression [closed]

Consider the following trivial example: ...
Shredderroy's user avatar
  • 5,251
19 votes
2 answers
1k views

How do the functions Reap and Sow actually work behind the scenes?

I have read that using Reap and Sow to generate a list of unknown length is much more efficient than using AppendTo over and over. I believe AppendTo works by creating a new list that is one element ...
Cat Bisque's user avatar
2 votes
0 answers
67 views

Can I parallelize this function?

Can I and should I parallelize this function ? my aim is to have faster calculations below is a toy function in which I kept the structure of the real function I am using. It uses ...
DarkBulle's user avatar
  • 1,014
1 vote
1 answer
72 views

Getting columns (instead of rows) using Reap/Sow

In my program, I'm computing a vector inside a Do loop. The example below is an overly-simplified version, but the structure is the same (the original code can't be ...
Anthill's user avatar
  • 37
0 votes
0 answers
72 views

Problems with NDSolve and initial conditions (NDSolve::nbnum1:)

this is the situation, I'm trying to solve a system (s1) with two differential equations, called "x[Ne]" and "y[Ne]". They have and initial condition that first need to satisfy ...
Matías López's user avatar
10 votes
1 answer
388 views

How to pick consecutive numbers from list?

Question is very simple. If we have tst = {2,3,4,6,7,9,11} result must be {{2,3,4}, {6,7}, {9}, {11}} There are similar ...
lesobrod's user avatar
  • 1,729
0 votes
1 answer
80 views

Why Reap and Sow is not working here [closed]

Here in the first example my code works: Reap[ For[x = 1, x <= 10, x++, f[x]; Sow[{x, f[x]}]]][[2, 1]]` and I can plot $x$ vs $f(x)$. However, ...
wahlang's user avatar
  • 11
1 vote
0 answers
170 views

How to use Reap and Sow with ParallelDo

Consider the two cases: ...
mattiav27's user avatar
  • 6,747
9 votes
1 answer
194 views

Accessing sowed data during long computation

This question is very similar to the one posted here: Interrogating a running evaluation but my running computation consists of a backtracking procedure which sows valid solutions. It is hard to tell ...
Gert's user avatar
  • 1,580
0 votes
0 answers
42 views

What is the meaning of [ ][[ ]]? [duplicate]

I have a question about these two pieces of code Reap[ For[i = 1, i < 10, i++, Sow[i]; Sow[i^2]; Sow[i!]; Sow[N@Log@i]]; ][[2, 1]] ~ Partition ~ 4 and <...
Hossain Sultani's user avatar
6 votes
3 answers
1k views

How to Sow[] until I've Reap[]'d enough?

I have a process that returns an unpredictable number of data points, and I'd like to run it repeatedly until I have a certain number of points. My actual code is too complicated to use an ...
Jerry Guern's user avatar
  • 4,612
1 vote
2 answers
140 views

How to assign output of `Last@Reap` to a variable? [closed]

I would like to define a variable that equals the solution of a numerical equation. Usually something like smax=zmax/.FindRoot[Exp[-zmax/2]==2,{zmax,0}] would work. ...
Sander Heinsalu's user avatar
0 votes
1 answer
158 views

I need an alternative to AppendTo using Reap and Sow

c = Table[RandomVariate[BernoulliDistribution[1/2], 3], 3] d = Total[c, {2}] list = {}; For[k = 0, k <= Length[d], k++, If[d[[k]] == 2, AppendTo[list, c[[k]]]]] ...
Chloe's user avatar
  • 1
2 votes
1 answer
164 views

Reap and sow for BreadthFirstSearch

The following Code highlights the breadth-first scan tree ...
ExpressionCoder's user avatar
2 votes
2 answers
125 views

How to control which list Sow puts elements in

I'm trying to Reap/Sow elements of a list into separate sub-lists. In this toy example, I want evens in one list, odds in the other. But whichever sub-list d[[1]] happened to belong in, that sub-...
Jerry Guern's user avatar
  • 4,612
4 votes
2 answers
227 views

Reap and Sow Tags. How to retrieve part of list belonging to specific tag? [closed]

I'm trying to improve my code's performance by using reap and sow instead of appendto and it works, but I hit a small obstacle. Since my code is building two lists simultaneously, I need to use sow ...
Diego's user avatar
  • 155
11 votes
1 answer
2k views

How to use Reap and Sow instead of Append to

I have matrix and and i want to do increment in a do loop and and i want to store in list using append to. It works fine for less values, But when i want to do it for values around 1 million the ...
revanth roy's user avatar
25 votes
1 answer
4k views

Understanding Sow and Reap documentation

Both in Sow and in Reap documentation there is the example: ...
mattiav27's user avatar
  • 6,747
1 vote
1 answer
293 views

WhenEvent, Storing Sow data, Loops

My problem is essentially to do with manipulating and storing Sow data in a nested loop structure. I have a set of differential equations describing time-evolution of a bunch of variables. ...
SarahThompson's user avatar
9 votes
1 answer
604 views

Better definitions of Reap and Sow

I am having tremendous difficulty understanding Reap and Sow in Mathematica. The definitions are pretty circular. When I look at the definition of Sow, I get, "specifies that e should be collected by ...
user avatar
3 votes
1 answer
116 views

Poor performance from Manipulate and Sow-Reap

I am not a mathematician, and I barely know how to use Mathematica. But, over the course of many months and with help from this site awhile back, I managed to generate dynamic output that does exactly ...
kwsockman's user avatar
  • 121
4 votes
2 answers
276 views

Sow in WhenEvent can't extract parameter value of ParametricNDSolve

This is a problem I noticed when trying to answer this question. Just consider the following toy example: ...
xzczd's user avatar
  • 67k
6 votes
3 answers
291 views

How to keep building list until manually stopped?

I would like to run a numerical experiment for as much as it can run in a reasonable time. This is a sketch of how I currently do it: ...
Džuris's user avatar
  • 325
5 votes
1 answer
211 views

Timing functions with Sow / Reap and AbsoluteTiming

I have a main function f[x] that calls three sub-functions: ...
ConvexMartian's user avatar
1 vote
1 answer
121 views

Reap unpacks packed arrays

I noticed that Reap unpacks packed arrays. I've looked at previous answers but am still an unsure whether this a serious issue. E.g. consider Ex 47.3 from EIWL: ...
TheDoctor's user avatar
  • 2,870
4 votes
1 answer
807 views

Writing Faster Mathematica Code - Sow and Reap?

I am applying Select function to a large list called xyCoordinateCentreCircle. The dimensions of the list are: ...
SPIL's user avatar
  • 657
9 votes
1 answer
508 views

Why is Reap result nested? [closed]

A minimal (toy) example for my question: i= 1; Reap[Do[Sow[i = (i + 1)^2], {4}]] (* {Null, {{4, 25, 676, 458329}}} *) I presume the entire result is a ...
murray's user avatar
  • 12k
18 votes
1 answer
2k views

Reap, Sow with Parallelize: bad performance, why?

I have a question about the performance of Reap and Sow with Parallelize. I am aware of the following questions How to collect result continuously (interruptible calculation) when running parallel ...
Mauricio Fernández's user avatar
10 votes
1 answer
163 views

Is Sow/Reap compatible with Composition?

I'm trying to figure out why these two pieces of code return different results. As expected, f[Reap[Sow[x]]] gives ...
rhennigan's user avatar
  • 1,783
4 votes
1 answer
398 views

Elements in `Reap` and `Sow`

Can someone help explain it to me: How does here e come out? Why b disappears? ...
Lawerance's user avatar
  • 517
13 votes
1 answer
705 views

Defining Tags in Reap

I am trying to use Sow/Reap to replace Append in my code. The problem is that I need to ...
LiberatedDreamer's user avatar