Suppose I have an array A. I have a series of index pairs (a1, b1), (a2, b2) ... (an, bn)
I want to obtain all the sums of the elements between those pairs. i.e.
In the first instance I'd try the direct solution:
[np.sum(A[a:b]) for (a,b) in ab]
where ab is the sequence of pairs.
A[a:b] creates a view on the array; there's no copying of the data involved.
If this turns out to be too slow, please tell us more about the size of A, how many pairs of indices you expect to get, whether the (a,b) ranges tend to overlap, etc.