fn

div

Tensor
div(input: Tensor, other: Tensor | Scalar)
source

Element-wise true division with broadcasting and dtype promotion.

Computes input / other element-wise. Integer operands are promoted to a floating-point dtype. Division by zero produces +/-inf or NaN according to IEEE 754.

Parameters

inputTensor
Left operand.
otherTensor or scalar
Right operand. Broadcasts against input following the standard broadcasting rules; Python scalars are promoted to a tensor of matching dtype.

Returns

Tensor

Element-wise result with shape broadcast(input.shape, other.shape) and dtype determined by the usual type-promotion rules.

Notes

Mathematical definition:

outi=inputiotheri\text{out}_i = \frac{\text{input}_i}{\text{other}_i}

Autograd: out/input=1/other\partial \text{out}/\partial \text{input} = 1/\text{other}, out/other=input/other2\partial \text{out}/\partial \text{other} = -\text{input}/\text{other}^{2}.

Examples

>>> import lucid
>>> a = lucid.tensor([1.0, 2.0, 3.0])
>>> b = lucid.tensor([4.0, 5.0, 6.0])
>>> lucid.div(a, b)
Tensor([...])