Multiple cumulative sum within a numpy array
问题 I'm sort of newbie in numpy so I'm sorry if this question was already asked. I'm looking for a vectorization solution which enable to run multiple cumsum of different size within a one dimension numpy array. my_vector=np.array([1,2,3,4,5]) size_of_groups=np.array([3,2]) I would like something like np.cumsum.group(my_vector,size_of_groups) [1,3,6,4,9] I do not want a solution with loops. Either numpy functions or numpy operations. 回答1: Not sure about numpy, but pandas can do this pretty easily