I have a dictionary with tensor keys and tensor values. I want to access the values by the keys.
from torch import tensor
x = {tensor(0): [tensor(1)], tensor(1): [tensor(0)]}
for i in x.keys():
print(i, x[i])
Returns:
tensor(0) [tensor(1)]
tensor(1) [tensor(0)]
But when i try to access the values without looping through the keys,
try:
print(x[tensor(0)])
except:
print(Exception)
print(x[0])
Throws Exception:
KeyError Traceback (most recent call last)
<ipython-input-34-746d28dcd450> in <module>()
6 try:
----> 7 print(x[tensor(0)])
8
KeyError: tensor(0)
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-34-746d28dcd450> in <module>()
9 except:
10 print(Exception)
---> 11 print(x[0])
12 continue
KeyError: 0