mindspore.ops.cumsum

查看源文件
mindspore.ops.cumsum(x, axis, dtype=None)[源代码]

返回tensor在指定轴上累积的元素和。

yi=x1+x2+x3+...+xi
参数:
  • x (Tensor) - 输入tensor。

  • axis (int) - 指定计算的轴。

  • dtype (mindspore.dtype, 可选) - 返回的数据类型。默认 None

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> input = mindspore.tensor([[1, 2, 3],
...                           [4, 5, 6]])
>>> mindspore.ops.cumsum(input, axis=0)
Tensor(shape=[2, 3], dtype=Int64, value=
[[1, 2, 3],
 [5, 7, 9]])
>>> mindspore.ops.cumsum(input, axis=1)
Tensor(shape=[2, 3], dtype=Int64, value=
[[ 1,  3,  6],
 [ 4,  9, 15]])