Function Differences with tf.math.cumsum

View Source On Gitee

tf.math.cumsum

tf.math.cumsum(x, axis=0, exclusive=False, reverse=False, name=None) -> Tensor

For more information, see tf.math.cumsum.

mindspore.ops.cumsum

mindspore.ops.cumsum(x, axis, dtype=None) -> Tensor

For more information, see mindspore.ops.cumsum.

Differences

TensorFlow: Calculates the cumulative sum of the input Tensor on the specified axis.

MindSpore: MindSpore API basically implements the same function as TensorFlow, and there are differences in parameter settings.

Categories

Subcategories

TensorFlow

MindSpore

Differences

Parameters

Parameter 1

x

x

-

Parameter 2

axis

axis

MindSpore has no default value and can specify dimensions

Parameter 3

exclusive

-

MindSpore does not have this parameter

Parameter 4

reverse

-

MindSpore does not have this parameter

Parameter 5

name

-

Not involved

Parameter 6

-

dtype

Setting the output data type in MindSpore

Code Example 1

The same input tensor, with axis -1, accumulates the innermost layer of the input tensor from left to right, and the two APIs achieve the same function.

# TensorFlow
import tensorflow as tf
a = tf.constant([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]])
y = tf.cumsum(a, -1)
print(y.numpy())
# [[ 3  7 13 23]
#  [ 1  7 14 23]
#  [ 4  7 15 22]
#  [ 1  4 11 20]]

# MindSpore
from mindspore import Tensor
import mindspore.ops as ops
import numpy as np
x = Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]))
y = ops.cumsum(x, -1)
print(y)
# [[ 3  7 13 23]
#  [ 1  7 14 23]
#  [ 4  7 15 22]
#  [ 1  4 11 20]]