TensorDictBase.fill#
- TensorDictBase.fill_(key: NestedKey, value: float | bool) Self#
Fills the entry at
keywithvaluein place and returnsself.If
keypoints to a nested tensordict, every leaf of it is filled.- Parameters:
- Raises:
KeyError – if
keyis missing.
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(2), b=TensorDict(c=torch.zeros(2))) >>> td.fill_("a", 1.0)["a"] tensor([1., 1.]) >>> td.fill_("b", 2.0)["b", "c"] tensor([2., 2.])
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.