Rate this Page
★ ★ ★ ★ ★

TensorDictBase.get_at#

TensorDictBase.get_at(key, index)#
TensorDictBase.get_at(key, index, default)

Get the value of a tensordict from the key key at the index idx.

Parameters:
  • key (str, tuple of str) – key to be retrieved.

  • index (int, slice, Tensor, iterable) – index of the tensor.

  • default (Tensor) – default value to return if the key is not present in the tensordict.

Returns:

indexed tensor.

Examples

>>> import torch
>>> from tensordict import TensorDict
>>> td = TensorDict({"x": torch.arange(3)}, batch_size=[])
>>> td.get_at("x", index=1)
tensor(1)

Every tensordict class and every tensorclass has this method. For the other methods, see Methods by task.

Tutorials that use get_at#

Storing TensorDicts in zarr

Storing TensorDicts in zarr