cumsum

dragon.math.cumsum(
  inputs,
  axis=0,
  exclusive=False,
  reverse=False,
  **kwargs
)[source]

Compute the cumulative sum of elements along the given axis.

The argument axis could be negative:

x = dragon.constant([[1, 2, 3], [4, 5, 6]])

# A negative axis is the last-k axis
print(dragon.math.cumsum(x, 1))   # [[1, 3, 6], [4, 9, 15]]
print(dragon.math.cumsum(x, -1))  # Equivalent

To exclude the top element, set the exclusive:

x = dragon.constant([1, 2, 3])
print(dragon.math.cumsum(x, exclusive=True))  # [0, 1, 3]

Also, reverse could be set to reverse the cumulative direction:

x = dragon.constant([1, 2, 3])
print(dragon.math.cumsum(x))  # [1, 3, 6]
print(dragon.math.cumsum(x, reverse=True))  # [6, 5, 3]
print(dragon.math.cumsum(x, exclusive=True, reverse=True))  # [5, 3, 0]
Parameters:
  • inputs (dragon.Tensor) – The input tensor.
  • axis (int, optional, default=0) – The cumulative axis.
  • exclusive (bool, optional, default=False) – True to exclude the top element.
  • reverse (bool, optional, default=False) – True to compute in the reverse direction.
Returns:

dragon.Tensor – The output tensor.