cumsum¶
dragon.vm.tensorflow.math.
cumsum
(
x,
axis=0,
exclusive=False,
reverse=False,
name=None
)[source]¶Compute the cumulative sum of elements along the given axis.
The argument
axis
could be negative:x = tf.constant([[1, 2, 3], [4, 5, 6]]) # A negative axis is the last-k axis print(tf.math.cumsum(x, 1)) # [[1, 3, 6], [4, 9, 15]] print(tf.math.cumsum(x, -1)) # Equivalent
To exclude the top element, set the
exclusive
:x = tf.constant([1, 2, 3]) print(tf.math.cumsum(x, exclusive=True)) # [0, 1, 3]
Also,
reverse
could be set to reverse the cumulative direction:x = tf.constant([1, 2, 3]) print(tf.math.cumsum(x)) # [1, 3, 6] print(tf.math.cumsum(x, reverse=True)) # [6, 5, 3] print(tf.math.cumsum(x, exclusive=True, reverse=True)) # [5, 3, 0]
- Parameters:
- x (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. - name (str, optional) – The operation name.
- Returns:
dragon.Tensor – The output tensor.