我有一个大列表2d列表,并尝试查找行的累加总和。累加总和应仅用于预定窗口(24),然后在下一个窗口重新启动。 问题是当我使用numpy cumsum时,例如在这里(索引3之后),我将无法重新启动该窗口后的总和。 任何帮助将不胜感激
import numpy as np
a=([[1,1,6,7,3,9,1],
[2,1,0,1,0,1,2],
[3,1,6,7,3,9,3],
[4,0,0,0,0,0,4],
[5,1,6,7,3,9,5],
[6,1,6,7,3,9,6],
[10,1,0,1,0,1,10]])
c = np.cumsum(a, axis = 0)
c[3:] = c[3:]- c[:-3]
print 'c',c
结果:
c[[ 1 1 6 7 3 9 1]
[ 3 2 6 8 3 10 3]
[ 6 3 12 15 6 19 6]
[ 9 2 6 8 3 10 9]
[12 2 12 14 6 18 12]
[15 2 12 14 6 18 15]
[21 3 12 15 6 19 21]]
结果应在每个窗口之后重新启动(3) 预期结果应该是
c=[[ 1 1 6 7 3 9 1]
[ 3 2 6 8 3 10 3]
[ 6 3 12 15 6 19 6]
[ 4 0 0 0 0 0 4]
[ 9 1 6 7 3 19 9]
[15 2 12 14 6 18 15]
[ 9 1 6 7 3 9 9 ]]