If I have an array [a,b,c], how can I convert it to [a+b+c, b+c, c] in the most efficient way?
(a, b, c) are floats.
Thanks!
>Solution :
You can use np.cumsum:
import numpy as np
a = np.array([1, 2, 3])
print(np.cumsum(a[::-1])[::-1])
# Outputs [6 5 3]