Try the following:
from torch.autograd import Variable
import torch
print(torch.__version__)
# 0.2.0_1

x = torch.rand(4, 6)
x = Variable(x)
y = torch.rand(4*6)
y = Variable(y)

mask = x > 0.5

def fun(y, mask):
    y = y.view(4, 6).clone()
    y[mask] = -1.0
    return y


fun(y, mask)

The problem is you can’t (yet) perform in-place operations on a view. My above snippet clones the view so that it is its own tensor.