TensorDictBase.del#
- TensorDictBase.del_(key: NestedKey) Self#
Deletes a key of the tensordict.
A locked tensordict raises
RuntimeError(seelock_()).- Parameters:
key (NestedKey) – key to be deleted. A missing key raises
KeyError, and a key whose path runs through an entry that is not a tensordict raisesValueError. Until 0.17, the stores and the zarr backend ofPersistentTensorDictwarn and do nothing for a missing key.- Returns:
self
Examples
>>> import torch >>> from tensordict import TensorDict >>> td = TensorDict(a=torch.zeros(3), b=TensorDict(c=torch.ones(3))) >>> list(td.del_(("b", "c")).keys(True)) ['a', 'b']
Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.