megengine.functional.cumsum

cumsum(inp, axis)[源代码]

Computes the cumulative sum of elements along given axis.

参数
  • inp (Tensor) – input tensor.

  • axis (int) – axis along which cumsum is performed.

实际案例

from megengine import tensor
import megengine.functional as F

x = tensor([[1, 2, 3], [4, 5, 6]], "int32")
y = F.cumsum(x, 1)
print(y.numpy())

Outputs:

[[ 1  3  6]
[ 4  9 15]]