pyodide/benchmark/benchmarks/reverse_cumsum.py

10 lines
300 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# http://stackoverflow.com/questions/16541618/perform-a-reverse-cumulative-sum-on-a-numpy-array
# pythran export reverse_cumsum(float[])
# setup: import numpy as np ; r = np.random.rand(1000000)
# run: reverse_cumsum(r)
2018-04-05 22:07:33 +00:00
import numpy as np
2018-10-03 12:38:48 +00:00
2018-10-03 18:59:01 +00:00
2018-04-05 22:07:33 +00:00
def reverse_cumsum(x):
return np.cumsum(x[::-1])[::-1]