# 比较与tf.math.divide的功能差异

## tf.math.divide

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

## mindspore.ops.div

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

## 差异对比

TensorFlow：将两个Tensor进行逐元素相除取商的操作。

MindSpore：当MindSpore的该API的参数rounding_mode为默认值None时，MindSpore此API实现功能与TensorFlow一致。

TensorFlow

MindSpore

x

input

y

other

-

rounding_mode

TensorFlow中无此参数。MindSpore为可选参数，用于决定结果的舍入类型，默认值为None

name

-

### 代码示例

```# 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 ]]
```