I am trying to access multiple elements in a 3D-Pytorch-Tensor, but the number of elements that are returned is wrong.
This is my code:
import torch
a = torch.FloatTensor(4,3,2)
print("a = {}".format(a))
print("a[:][:][0] = {}".format(a[:][:][0]))
This is the output:
a = tensor([[[-4.8569e+36, 3.0760e-41],
[ 2.7953e+20, 1.6928e+22],
[ 3.1692e-40, 7.2945e-15]],
[[ 2.5011e+24, 1.3173e-39],
[ 1.7229e-07, 4.1262e-08],
[ 4.1490e-08, 6.4103e-10]],
[[ 3.1728e-40, 5.8258e-40],
[ 2.8776e+32, 6.7805e-10],
[ 3.1764e-40, 5.4229e+08]],
[[ 7.2424e-37, 1.3697e+07],
[-2.0362e-33, 1.8146e+11],
[ 3.1836e-40, 1.9670e+34]]])
a[:][:][0] = tensor([[-4.8569e+36, 3.0760e-41],
[ 2.7953e+20, 1.6928e+22],
[ 3.1692e-40, 7.2945e-15]])
I would expect something like this:
a[:][:][0] = tensor([[-4.8569e+36, 2.7953e+20, 3.1692e-40,
2.5011e+24, 1.7229e-07, 4.1490e-08,
3.1728e-40, 2.8776e+32, 3.1764e-40,
7.2424e-37, -2.0362e-33, 3.1836e-40]])
Can anyone explain to me how I can come to this result? Thank you very much in advance!
I get exactly the expected result on performing:
for i in range(4):
for j in range(3):
print("a[{}][{}][0] = {}".format(i,j, a[i][j][0]))