Rate this Page
★ ★ ★ ★ ★

TensorDictBase.div#

TensorDictBase.div(other: TensorDictBase | Tensor, *, default: str | Tensor | TensorCollection | None = None) → Self#

Returns a new tensordict with every leaf divided by other.

td / other calls this method. Integer leaves are promoted to the default floating-point dtype, as with torch.div().

\[\text{out}_i = \frac{\text{input}_i}{\text{other}_i}\]
Parameters:

other (TensorDictBase, Tensor or Number) – the divisor. A tensordict is paired with the tensordict key by key. A tensor is aligned with the batch dimensions of each leaf and expanded over its feature dimensions. Batch sizes that differ are broadcast together.

Keyword Arguments:

default (Tensor or str, optional) – what to do with the keys that only one of the two tensordicts has. None requires the same keys and raises a KeyError otherwise. "intersection" computes the keys that both have and drops the others. A tensor stands in for the missing entry on either side, and the result has the keys of both. Defaults to None.

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.