mindspore.mint.cumsum
- mindspore.mint.cumsum(input, dim, dtype=None)[源代码]
返回tensor在指定维度上累积的元素和。
\[y_i = x_1 + x_2 + x_3 + ... + x_i\]- 参数:
input (Tensor) - 输入tensor。
dim (int) - 指定计算维度。
dtype (
mindspore.dtype, 可选) - 指定数据类型。默认None。
- 返回:
Tensor
- 支持平台:
Ascend
样例:
>>> import mindspore >>> x = mindspore.tensor([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]) >>> # case 1: along the dim 0 >>> mindspore.mint.cumsum(x, 0) Tensor(shape=[4, 4], dtype=Int64, value= [[ 3, 4, 6, 10], [ 4, 10, 13, 19], [ 8, 13, 21, 26], [ 9, 16, 28, 35]]) >>> # case 2: along the dim 1 >>> mindspore.mint.cumsum(x, 1) Tensor(shape=[4, 4], dtype=Int64, value= [[ 3, 7, 13, 23], [ 1, 7, 14, 23], [ 4, 7, 15, 22], [ 1, 4, 11, 20]])