pan><span class="n">sum</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
  <span class="n">S</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cumsum</span><span class="p">(</span><span class="n">S</span><span class="p">)</span>
  <span class="n">S</span> <span class="o">=</span> <span class="n">S</span> <span class="o">/</span> <span class="n">total</span>
  <span class="n">S</span> <span class="o">=</span> <span class="n">S</span