Indexing a Variable on multiple dimensions

Hello !

Given an autograd Variable idx with several 3-dimensional indices and a 3-dimensional Variable data, I would like to do something similar as:

import torch
from torch.autograd import Variable
x = Variable(torch.randn(3,3), requires_grad=True)
idx = Variable(torch.LongTensor([[0,1], [0,0]]))

x[idx] = [0, 0]

Is there a way to change the values of the N positions specified by idx in x by N values specified by another variable?

Thank you.

I think you’re looking for masked_scatter_

1 Like

@richard Thank you, that’s not exactly what I am searching for but it may work.