Understand tf.cumsum(): Compute the Cumulative Sum of The Tensor – TensorFlow Tutorial

By | January 4, 2021

TensorFlow tf.cumsum() allows us to compute the cumulative sum of the tensor x along axis. In this tutorial, we will use some examples to show you how to use it.

Syntax

tf.cumsum() is defined as:

tf.cumsum(
    x,
    axis=0,
    exclusive=False,
    reverse=False,
    name=None
)

Compute the cumulative sum of the tensor x along axis

We will use some examples to show you how to use this function.

Default Parameters

tf.cumsum([a, b, c])

The result will be:

[a, a + b, a + b + c]

exclusive = True

tf.cumsum([a, b, c], exclusive=True)

The result will be:

[0, a, a + b]

reverse = True

tf.cumsum([a, b, c], reverse=True)

It will be:

[a + b + c, b + c, c]

exclusive = True and reverse = True

tf.cumsum([a, b, c], exclusive=True, reverse=True)

The result will be:

[b + c, c, 0]

Leave a Reply