oneflow.cumsum

oneflow.cumsum(input, dim)Tensor

This operator computes the cumulative sum of input elements in the given dimension.

The equation is:

$$ y_{i}=x_{0}+x_{1}+…+x_{i} $$

Parameters
  • input (Tensor) – the input ND tensor.

  • dim (int) – the dimension to do cumsum, valid range is [-N, N-1), N is tensor’s dimensions

Returns

The result tensor with cumsum result.

Return type

oneflow.Tensor

For example:

>>> import oneflow as flow
>>> input = flow.ones(3, 3)
>>> dim = 1
>>> flow.cumsum(input, dim)
tensor([[1., 2., 3.],
        [1., 2., 3.],
        [1., 2., 3.]], dtype=oneflow.float32)