Wednesday, June 10, 2026
HomeLanguagesPython – tensorflow.math.cumulative_logsumexp()

Python – tensorflow.math.cumulative_logsumexp()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

cumulative_logsumexp() is used to calculate the cumulative log-sum-exp of input tensor. This operation is equivalent to tensorflow.math.log( tensorflow.math.cumsum( tensorflow.math.exp(x))) but it is numerically more stable.

Syntax: tensorflow.math.cumulative_logsumexp(   x, axis, exclusive, reverse, name)

Parameters: 

  • x: It’s the input tensor. Allowed dtypes for this tensor are  float16, float32, float64.
  • axis(optional): It’s a tensor of type int32. It’s value should  be in the range  A Tensor of type int32 (default: 0). Must be in the range [-rank(x), rank(x)).  Default value is 0.
  • exclusive(optional): It’s of type bool. Default value is False.
  • reverse(optional): It’s of type bool. Default value is False.
  • name(optional): It defines the name for the operation.

Returns:

It returns a tensor of same dtype as x.

Example 1:

Python3




# importing the library
import tensorflow as tf
 
# initializing the input
a = tf.constant([1, 2, 4, 5], dtype = tf.float64) 
 
# Printing the input
print("Input: ",a)
 
# Cumulative log-sum-exp
res  = tf.math.cumulative_logsumexp(a)
 
# Printing the result
print("Output: ",res)


Output:

Input:  tf.Tensor([1. 2. 4. 5.], shape=(4,), dtype=float64)
Output:  tf.Tensor([1.         2.31326169 4.16984602 5.36184904], shape=(4,), dtype=float64)

Example 2: In this example both reverse and exclusive are set to True.

Python3




# importing the library
import tensorflow as tf
 
# initializing the input
a = tf.constant([2, 3, 4, 5], dtype = tf.float64) 
 
# Printing the input
print("Input: ",a)
 
# Cumulative log-sum-exp
res  = tf.math.cumulative_logsumexp(a, reverse = True, exclusive = True)
 
# Printing the result
print("Output: ",res)


Output: 

Input:  tf.Tensor([2. 3. 4. 5.], shape=(4,), dtype=float64)
Output:  tf.Tensor([ 5.40760596e+000  5.31326169e+000  5.00000000e+000 -1.79769313e+308], shape=(4,), dtype=float64)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6896 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS