mindspore.ops.div

View Source On Gitee
mindspore.ops.div(input, other, *, rounding_mode=None)[source]

Divide the first input tensor by the second input tensor in floating-point type element-wise.

outi=inputi/otheri

Note

  • The two input tensors must be broadcastable.

  • The two input tensors can not be bool type at the same time,

  • The two input tensors comply with the implicit type conversion rules to make the data types consistent.

Parameters
  • input (Union[Tensor, Number, bool]) – The first input tensor.

  • other (Union[Tensor, Number, bool]) – The second input tensor.

Keyword Arguments

rounding_mode (str, optional) –

Type of rounding applied to the result. Default None . Three types are defined as:

  • None: the same as true division in Python or true_divide in NumPy.

  • "floor": rounds the results of the division down, which is the same as floor division in Python or floor_divide in NumPy.

  • "trunc": rounds the results of the division towards zero, which is the same as C-style integer division.

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> 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.]]