Rate this Page
★ ★ ★ ★ ★

TensorDictBase.del#

TensorDictBase.del_(key: NestedKey) → Self#

Deletes a key of the tensordict.

A locked tensordict raises RuntimeError (see lock_()).

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 raises ValueError. Until 0.17, the stores and the zarr backend of PersistentTensorDict warn 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.

Tutorials that use del_#

Getting, setting, and nesting keys

Getting, setting, and nesting keys