334 Star 1.5K Fork 864

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
div.md 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
luojianing 提交于 2023-07-21 15:16 . replace target=blank

Function Differences with tf.math.divide

View Source On Gitee

tf.math.divide

tf.math.divide(x, y, name=None) -> Tensor

For more information, see tf.math.divide.

mindspore.ops.div

mindspore.ops.div(input, other, rounding_mode=None) -> Tensor

For more information, see mindspore.ops.div.

Differences

TensorFlow: The quotient is obtained by dividing two Tensors element-wise.

MindSpore: When the parameter rounding_mode of MindSpore API is None by default, MindSpore implements the same function as TensorFlow.

Categories Subcategories TensorFlow MindSpore Differences
Parameters Parameter 1 x input Same function, different parameter names
Parameter 2 y other Same function, different parameter names
Parameter 3 - rounding_mode This parameter is not available in TensorFlow. MindSpore is an optional parameter that determines the rounding type of the result, and the default value is None
Parameter 4 name - Not involved

Code Example

When the parameter rounding_mode of MindSpore is not specified, the two APIs achieve the same function and have the same usage.

# TensorFlow
import tensorflow as tf
import numpy

x = tf.constant([[2, 4, 6, 8], [1, 2, 3, 4]])
y = tf.constant([5, 8, 8, 16])
out = tf.math.divide(x, y).numpy()
print(out)
# [[0.4   0.5   0.75  0.5  ]
#  [0.2   0.25  0.375 0.25 ]]

# MindSpore
import mindspore
from mindspore import Tensor
import mindspore.ops as ops
import numpy as np

x_ = np.array([[2, 4, 6, 8], [1, 2, 3, 4]])
y_ = np.array([5, 8, 8, 16])
x = Tensor(x_, mindspore.float64)
y = Tensor(y_, mindspore.float64)
output = ops.div(x, y)
print(output)
# [[0.4   0.5   0.75  0.5  ]
#  [0.2   0.25  0.375 0.25 ]]
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r2.0

搜索帮助