Python - tensorflow.math.cumsum() Last Updated : 22 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. cumsum() is used to calculate the cumulative sum of input tensor. Syntax: tensorflow.math.cumsum(x, axis, exclusive, reverse, name) Parameters: x: It's the input tensor. Allowed dtype for this tensor are float32, float64, int64, int32, uint8, uint16, int16, int8, complex64, complex128, qint8, quint8, qint32, half.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 and if set to true then the output for input [a, b, c] will be [0, a, a+b].reverse(optional): It's of type bool. Default value is False and if set to true then the output for input [a, b, c] will be [a+b+c, a+b, a].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.int32) # Printing the input print("Input: ",a) # Cumulative sum res = tf.math.cumsum(a) # Printing the result print("Output: ",res) Output: Input: tf.Tensor([1 2 4 5], shape=(4,), dtype=int32) Output: tf.Tensor([ 1 3 7 12], shape=(4,), dtype=int32) 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.int32) # Printing the input print("Input: ",a) # Cumulative sum res = tf.math.cumsum(a, reverse = True, exclusive = True) # Printing the result print("Output: ",res) Output: Input: tf.Tensor([2 3 4 5], shape=(4,), dtype=int32) Output: tf.Tensor([12 9 5 0], shape=(4,), dtype=int32) Comment More infoAdvertise with us Next Article Python - tensorflow.math.cumulative_logsumexp() A aman neekhara Follow Improve Article Tags : Machine Learning AI-ML-DS With Python Practice Tags : Machine Learning Similar Reads Python - tensorflow.math.cumprod() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.  cumprod() is used to calculate the cumulative product of input tensor. Syntax: tensorflow.math.cumprod(  x, axis, exclusive, reverse, name) Parameters: x: It's the in 2 min read Python - tensorflow.math.expm1() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. expm1() is used to compute element wise exp(x)-1. Syntax: tensorflow.math.expm1(  x, name) Parameters: x: It's the input tensor. Allowed dtypes are bfloat16, half, flo 1 min read Python - tensorflow.math.bincount() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. bincount() is present in TensorFlow's math module. It is used to count occurrences of each number in integer array. Syntax: tensorflow.math.bincount( arr, weights, minle 2 min read 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( ten 2 min read Python - tensorflow.math.log1p() TensorFlow is open-source python library designed by Google to develop Machine Learning models and deep learning  neural networks. TensorFlow raw_ops provides low level access to all TensorFlow operations. Log1p() is used to find element wise logarithm of (1+x) for input x. Syntax: tf.math.log1p(x, 2 min read Python - tensorflow.math.floormod() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. floormod() is used to compute element wise remainder of division of x by y. Syntax: tensorflow.math.floormod( x, y, name) Parameters: x: It is a tensor. Allowed dtypes 2 min read Like