TensorDictBase.where#
- TensorDictBase.where(condition: Tensor, other: Tensor | TensorDictBase, *, out: TensorDictBase | None = None, pad: int | bool = None, update_batch_size: bool = False) Self#
Return a
TensorDictof elements selected from either self or other, depending on condition.- Parameters:
condition (BoolTensor) – When
True(nonzero), yieldsself, otherwise yieldsother.other (TensorDictBase or Scalar) – value (if
otheris a scalar) or values selected at indices where condition isFalse. On aLazyStackedTensorDict, a tensorotherthat starts with the batch shape up to the stack dim is split along the stack dim, one piece per member, so it must also have the stack size at the stack dim: expand it to the batch shape first.
- Keyword Arguments:
out (TensorDictBase, optional) – the output
TensorDictBaseinstance.pad (scalar, optional) – if provided, missing keys from the source or destination tensordict will be written as torch.where(mask, self, pad) or torch.where(mask, pad, other). Defaults to
None, ie missing keys are not tolerated.update_batch_size (bool, optional) – if
Trueandoutis provided, the batch size of the output will be updated to match the batch size of the condition. Defaults toFalse.
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.