How to scatter elements of tensor into entries of another one, given an idx tensor?

I have 3 tensors, say T, Idx, V, where V is a K-long 1D tensor, T has arbitrary shape and numbers and Idx has the same shape as T, but contains index entries of V (that is, it has integers from 1 to K as elements). Now I would like to scatter each element of V into T as respectively stated in Idx. How can I do this?

I’m not sure how you would like to scatter the values into T, as I think just indexing V[Idx] might give you the output:

K = 10
V = torch.randn(K)
T = torch.randn(5, 5)
Idx = torch.empty(T.size(), dtype=torch.long).random_(K)

V[Idx]

Would this work for you?