Cumulative-Sum-to-the-End for each element in the array
<p>Suppose I have an array <code>a = array([a0, a1,..., an])</code>. For every element in the array, I need to find all cumulative sums in the direction from left to right. Thus, for <code>n=2</code> I have to find </p>

<p><code>a0, a0+a1, a0+a1+a2, a1, a1+a2, a2</code>. </p>

<p>The obvious approach is the following:</p>

<pre><code>list_of_sums = [np.cumsum(a[i:]) for i in xrange(n+1)]
</code></pre>

<p>I wonder if there exists a more efficient way to do this. The issue is that <code>n</code> may be quite large and in addition I want to broadcast this for many different arrays <code>a</code> of the same length. Unfortunately, I did not succeed to create a vectorized function for this.</p>

<p>Another problem is how to store all these sums. Instead of using list, we can represent all the data as <code>2D</code> array <code>A</code>, where in the first column <code>A[:,0]</code> I have all the sums with <code>a0</code> as the first term, in the second column <code>A[:,1]</code> I have all the sums with <code>a1</code> as the first term,  and so on. This gives us <code>(n+1)x(n+1)</code> matrix, half elements of which are zeros (the right lower triangle). On the other hand, this requires in 2 times more memory than list use, or force us to use sparse matrices that may be overkill.</p>