cumsum

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

Compute the cumulative sum of elements along the given axis.

axis could be negative:

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

Use exclusive to exclude the top element:

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

Use reverse 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 axis to cumulate.
  • exclusive (bool, optional, default=False) True to exclude the top element.
  • reverse (bool, optional, default=False) True to cumulate in a reverse direction.
Returns:

dragon.Tensor The output tensor.