# torch.div¶

torch.div(input, other, out=None) → Tensor

Divides each element of the input input with the scalar other and returns a new resulting tensor.

Warning

Integer division using div is no longer supported, and in a future release div will perform true division as in Python 3. Use torch.true_divide() or torch.floor_divide() (// in Python), instead.

$\text{out}_i = \frac{\text{input}_i}{\text{other}}$

If the torch.dtype of input and other differ, the torch.dtype of the result tensor is determined following rules described in the type promotion documentation. If out is specified, the result must be castable to the torch.dtype of the specified output tensor. Integral division by zero leads to undefined behavior.

Parameters
• input (Tensor) – the input tensor.

• other (Number) – the number to be divided to each element of input

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.randn(5)
>>> a
tensor([ 0.3810,  1.2774, -0.2972, -0.3719,  0.4637])
>>> torch.div(a, 0.5)
tensor([ 0.7620,  2.5548, -0.5944, -0.7439,  0.9275])

torch.div(input, other, out=None) → Tensor

Each element of the tensor input is divided by each element of the tensor other. The resulting tensor is returned.

$\text{out}_i = \frac{\text{input}_i}{\text{other}_i}$

The shapes of input and other must be broadcastable. If the torch.dtype of input and other differ, the torch.dtype of the result tensor is determined following rules described in the type promotion documentation. If out is specified, the result must be castable to the torch.dtype of the specified output tensor. Integral division by zero leads to undefined behavior.

Parameters
• input (Tensor) – the numerator tensor

• other (Tensor) – the denominator tensor

Keyword Arguments

out (Tensor, optional) – the output tensor.

Example:

>>> a = torch.randn(4, 4)
>>> a
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]])
>>> b = torch.randn(4)
>>> b
tensor([ 0.8032,  0.2930, -0.8113, -0.2308])
>>> torch.div(a, b)
tensor([[-0.4620, -6.6051,  0.5676,  1.2637],
[ 0.2260, -3.4507, -1.2086,  6.8988],
[ 0.1322,  4.9764, -0.9564,  5.3480],
[-0.2278, -0.1068, -1.4678,  6.3936]])