I have and 3D tensor:
inp = torch.rand(400,600,3)
I want to replace one of the dimensions by a 2D tensor like:
y = torch.zeros(x[:,:,1].shape)
I’m trying to index and replace like inp[:,:,1] = y
but instead I of one of the 400x600 it seems to replace one column across the whole 3D tensor:
inp
tensor([[[0.9132, 0.0000, 0.5986],
[0.2523, 0.0000, 0.1171],
[0.5549, 0.0000, 0.2875],
...,
[0.9777, 0.0000, 0.1527],
[0.5669, 0.0000, 0.9031],
[0.1303, 0.0000, 0.0252]],
[[0.0073, 0.0000, 0.8185],
[0.2140, 0.0000, 0.1950],
[0.0666, 0.0000, 0.6404],
...,
[0.3611, 0.0000, 0.1923],
[0.2869, 0.0000, 0.5641],
[0.8142, 0.0000, 0.1015]],
[[0.6172, 0.0000, 0.8202],
[0.0122, 0.0000, 0.5879],
[0.2285, 0.0000, 0.0171],
...,
[0.1347, 0.0000, 0.1469],
[0.1260, 0.0000, 0.1539],
[0.1876, 0.0000, 0.8285]],
...,
[[0.2957, 0.0000, 0.1658],
[0.6985, 0.0000, 0.1012],
[0.7452, 0.0000, 0.9366],
...,
[0.5743, 0.0000, 0.7877],
[0.5458, 0.0000, 0.1958],
[0.7182, 0.0000, 0.3096]],
[[0.1060, 0.0000, 0.1589],
[0.0132, 0.0000, 0.0222],
[0.4626, 0.0000, 0.4589],
...,
[0.8956, 0.0000, 0.6201],
[0.2406, 0.0000, 0.9843],
[0.0187, 0.0000, 0.4369]],
[[0.2071, 0.0000, 0.7130],
[0.7521, 0.0000, 0.7691],
[0.6274, 0.0000, 0.2580],
...,
[0.8197, 0.0000, 0.4061],
[0.3698, 0.0000, 0.2892],
[0.6189, 0.0000, 0.1528]]])
Why is this not throwing a dimension error? How should I change my code to get the desired output?
Thanks!