>>> a = V(torch.rand(5), requires_grad=True)
Variable containing:
 0.8491
 0.1877
 0.1560
 0.5188
 0.7464
[torch.FloatTensor of size 5]

>>> c = a[2] * 0
Variable containing:
 0
[torch.FloatTensor of size 1]

I need to end up with the same size…
I’ve also tried
>>> c = a.index_fill(0, 3, 0)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-25-ad8f493be136> in <module>()
----> 1 c = a.index_fill(0, 3, 0)

/home/atcold/anaconda3/lib/python3.5/site-packages/torch/autograd/variable.py in index_fill(self, dim, index, value)
    627 
    628     def index_fill(self, dim, index, value):
--> 629         return IndexFill(dim, value)(self, index)
    630 
    631     def index_fill_(self, dim, index, value):

RuntimeError: expected a Variable argument, but got int

The only think that worked is masking, but it’s not acceptable…
In [12]: mask = V(torch.Tensor([1, 1, 1, 0, 1]))

In [13]: b = a * mask

In [14]: b
Out[14]: 
Variable containing:
 0.8491
 0.1877
 0.1560
 0.0000
 0.7464
[torch.FloatTensor of size 5]

In [15]: m = b.mean()

In [16]: m
Out[16]: 
Variable containing:
 0.3879
[torch.FloatTensor of size 1]

In [17]: m.backward()

In [18]: a.grad
Out[18]: 
Variable containing:
 0.2000
 0.2000
 0.2000
 0.0000
 0.2000
[torch.FloatTensor of size 5]