Hi guys, I’m new here and I have a problem. I have a tensor with data mat
and an empty tensor of the same shape. I also have a 1D index tensor ‘ind’, which has indices of slices I want to copy. What I want to do is to look at index of a slice I want and put it in the same spot in the empy tensor.
mat = torch.arange(0,16).reshape(4,2,2)
empty = torch.zeros((4,2,2))
ind = torch.tensor([0,2])
The idea is to do something like this ( which I know is wrong, I’m new to this ):
empty[ind] = mat[ind]
so here the empty matrix should have first and third slices, while second and fourth slices should
remain empty ( or in this case filled with zeros ):
torch.tensor( [ [ [ 0, 1 ],
[ 2, 3 ] ],
[ [ 0 , 0 ],
[ 0 , 0 ] ],
[ [ 8, 9 ],
[10, 11 ] ],
[ [ 0 , 0 ],
[ 0 , 0 ] ] ] )
How do I solve this?
Thank you for your answers.