np.cumsum()的用法

↘锁芯ラ 提交于 2020-03-01 19:11:53

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!