I'm searching for a method to use itertools.accumulate in starmap.
I tried to calculate the accumulated sum of each row in a table, then concatenate the results to an array:
# my input
my_table = [[3, 5], [1, 4, 7], [2]]
# expected output
P = [3, 8, 1, 5, 12, 2]
I use itertools in a for loop, but it becomes much slower than other ways. So is it possible to use starmap or other itertools method make it quicker?
def getSums(my_table):
P = []
for i in range(len(my_table)):
P.append(itertools.accumulate(my_table[i]))
P = itertools.chain.from_iterable(P)
return P