megengine.functional.cumsum

cumsum(inp, axis)[源代码]

Calculates the cumulative sum of tensor elements over a given axis.

参数
  • inp (Tensor) – input tensor. Should have a numeric data type.

  • axis (int) – axis along which cumulative sums must be computed.

返回

a tensor containing the cumulative sums.

实际案例

If \(x_i\) is NaN, the cumulative sums is NaN (i.e., NaN values propagate).

实际案例

>>> x = Tensor([[1, 2, 3], [4, 5, 6]])
>>> F.cumsum(x, axis = 0)
Tensor([[1 2 3]
 [5 7 9]], dtype=int32, device=xpux:0)
>>> F.cumsum(x, axis = 1)
Tensor([[ 1  3  6]
 [ 4  9 15]], dtype=int32, device=xpux:0)