Hi I have a question about change the tensor value.
If I change the value of tensor this way, works well.
a=torch.zeros(5,3,2)
b=torch.Tensor([True,False,True,False,True]).bool()
a[b]=2 #shape 3,3,2
print(a)
###tensor([[[2., 2.],
[2., 2.],
[2., 2.]],
[[0., 0.],
[0., 0.],
[0., 0.]],
[[2., 2.],
[2., 2.],
[2., 2.]],
[[0., 0.],
[0., 0.],
[0., 0.]],
[[2., 2.],
[2., 2.],
[2., 2.]]])
However,why I cant change the value of tensor in this way?
a=torch.zeros(5,3,2)
b=torch.Tensor([True,False,True,False,True]).bool()
a[b][:,2,:]=2
print(a)
###
tensor([[[0., 0.],
[0., 0.],
[0., 0.]],
[[0., 0.],
[0., 0.],
[0., 0.]],
[[0., 0.],
[0., 0.],
[0., 0.]],
[[0., 0.],
[0., 0.],
[0., 0.]],
[[0., 0.],
[0., 0.],
[0., 0.]]])
My desired output is
Tensor([[[0., 0.],
[0., 0.],
[2., 2.]],
[[0., 0.],
[0., 0.],
[2., 2.]],
[[0., 0.],
[0., 0.],
[2., 2.]],
[[0., 0.],
[0., 0.],
[2., 2.]],
[[0., 0.],
[0., 0.],
[2., 2.]]])
Thanks in advance.