fromkeys#
- tensordict.fromkeys(keys: list[NestedKey], value: Any = 0)#
Creates a tensordict with the same value for every key, like
dict.fromkeys().Same as
tensordict.TensorDict.fromkeys(), and asdict.fromkeys()for a dict. The batch size of the result is[].- Parameters:
- Returns:
A
TensorDict.
Examples
>>> import tensordict >>> td = tensordict.fromkeys(["a", ("b", "c")], 1) >>> td["b", "c"] tensor(1)