for i in range(0, ilen):
    r.append(0)
i_list = [0, 0, 1, 2, 2]
d = [1, 1, 1, 1, 1]
result = zeros(max(i_list) + 1)
for index in i_list:
    result[index] += d[index]
print(result)
Cumulative summation of a numpy array by index