mindspore.ops.div

查看源文件
mindspore.ops.div(input, other, *, rounding_mode=None)[源代码]

逐元素计算第一个输入tensor除以第二个输入tensor。

outi=inputi/otheri

说明

  • 两个输入tensor的shape须可以进行广播。

  • 两个输入tensor不能同时为bool类型。

  • 两个输入tensor遵循隐式类型转换规则,使数据类型保持一致。

参数:
  • input (Union[Tensor, Number, bool]) - 第一个输入tensor。

  • other (Union[Tensor, Number, bool]) - 第二个输入tensor。

关键字参数:
  • rounding_mode (str, 可选) - 应用于计算结果的舍入类型。默认 None 。三种类型被定义为:

    • None:相当于Python中的 true division 或NumPy中的 true_divide

    • "floor":向下取整。相当于Python中的 floor division 或NumPy中的 floor_divide

    • "trunc":向0取整。相当于C语言风格的整数除法。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> input = mindspore.tensor([[-0.3711, -1.9353, -0.4605, -0.2917],
...                           [ 0.1815, -1.0111,  0.9805, -1.5923],
...                           [ 0.1062,  1.4581,  0.7759, -1.2344],
...                           [-0.1830, -0.0313,  1.1908, -1.4757]])
>>> other = mindspore.tensor([ 0.8032,  0.2930, -0.8113, -0.2308])
>>> output = mindspore.ops.div(input, other)
>>> print(output)
[[-0.4620269  -6.605119    0.5676076   1.2638649 ]
 [ 0.22597112 -3.4508533  -1.2085541   6.899047  ]
 [ 0.13222112  4.97645    -0.95636636  5.348354  ]
 [-0.22783864 -0.10682594 -1.4677677   6.3938475 ]]
>>> output = mindspore.ops.div(input, other, rounding_mode='floor')
>>> print(output)
[[-1. -7.  0.  1.]
 [ 0. -4. -2.  6.]
 [ 0.  4. -1.  5.]
 [-1. -1. -2.  6.]]