TensorDictBase.del#
- TensorDictBase.del_(key: NestedKey) Self#
Deletes an entry of the tensordict in place and returns the tensordict.
A locked tensordict raises
RuntimeError(seelock_()).del td[key]does the same.- Parameters:
key (NestedKey) – the key to delete. A missing key raises
KeyError, and a key whose path runs through an entry that is not a tensordict raisesValueError. Until TensorDict 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.