Given two integer arrays a and b, where the elements in b represent indices of a...
a = array([10,10,10,8,8,8])
b = array([0,2,3,5])
I want to generate a new array whose elements are the sums of the elements in a along the index ranges given in b, not including the element at the tail of the range... It's hard to put in words, but the expected result given a and b from above would be:
result = array([0, # sum(a[:0])
20, # sum(a[0:2])
10, # sum(a[2:3])
16]) # sum(a[3:5])
How could I achieve this in a vectorized/"numpythonic" way?
Thank you!