np.cumsum(a, axis = 0)用于将数组按行累加,譬如
import numpy as np
a = np.array([[1,2,3],[4,5,6]])
b = np.cumsum(a, axis=0)
print(b)
输出结果为
[[1 2 3]
[5 7 9]]
Process finished with exit code 0
np.cummsum(a, axis = 1)用于将数组按列累加,譬如
import numpy as np
a = np.array([[1,2,3],[4,5,6]])
b = np.cumsum(a, axis=1)
print(b)
输出结果为
[[ 1 3 6]
[ 4 9 15]]
Process finished with exit code 0