Tensorflow.js tf.cumsum() Function
The tf.cumsum() function is used to compute the cumulative sum of a tf.Tensor along the specified axis. The meaning of exclusive cumulative sum for a tensor is that each tensor entry does not include its own value, but only the values previous to it along the specified axis in the exclusive cumulative sum.
tf.cumsum(x, axis, exclusive, reverse)
Parameters: This method has four parameters as mentioned above and described below:
- x: The input tensor which has to be summed. It is of type tf.Tensor, TypedArray, or Array.
- axis: The axis along which we have to sum. It is an optional parameter. The default value is 0.
- exclusive: It decides whether to find an exclusive cumulative sum or not. It is a boolean value and defaults to false. It is an optional parameter.
- reverse: It decides whether to sum in the opposite direction. It is a boolean value and defaults to false. It is also an optional parameter.
Return Value: It returns a tf.Tensor denotes the cumulative sum of the given tensor.
The below examples demonstrate the tf.cumsum() method.
Tensor [1, 3, 6, 10]
Tensor [9, 7, 4, 0]
Tensor [[1, 2], [4, 6]]
Tensor [[1, 3], [3, 7]]