maxframe.tensor.cumsum#
- maxframe.tensor.cumsum(a, axis=None, dtype=None, out=None)[源代码]#
沿给定轴返回元素的累积和。
- 参数:
- 返回:
cumsum_along_axis —— 除非指定了 out,否则返回一个保存结果的新张量;若指定了 out,则返回对 out 的引用。结果与 a 大小相同,且当 axis 不为 None 或 a 为一维张量时,形状也相同。
- 返回类型:
Tensor.
备注
使用整数类型时,运算是模运算,溢出时不会引发错误。
示例
>>> import maxframe.tensor as mt
>>> a = mt.array([[1,2,3], [4,5,6]]) >>> a.execute() array([[1, 2, 3], [4, 5, 6]]) >>> mt.cumsum(a).execute() array([ 1, 3, 6, 10, 15, 21]) >>> mt.cumsum(a, dtype=float).execute() # specifies type of output value(s) array([ 1., 3., 6., 10., 15., 21.])
>>> mt.cumsum(a,axis=0).execute() # sum over rows for each of the 3 columns array([[1, 2, 3], [5, 7, 9]]) >>> mt.cumsum(a,axis=1).execute() # sum over columns for each of the 2 rows array([[ 1, 3, 6], [ 4, 9, 15]])