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
import tensorflow as tf
a = tf.constant([ 1 , 2 , 4 , 5 ], dtype = tf.float64)
print ( "Input: " ,a)
res = tf.math.cumulative_logsumexp(a)
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
import tensorflow as tf
a = tf.constant([ 2 , 3 , 4 , 5 ], dtype = tf.float64)
print ( "Input: " ,a)
res = tf.math.cumulative_logsumexp(a, reverse = True , exclusive = True )
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)
Last Updated :
22 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...