your mask is being automatically broadcasted to the shape of y. for masked_scatter_, the mask and y should be of the same shape. Also, masked_scatter_ doesn’t index into z, it sequentially copies over z's values
The more correct thing to do would be construct all ones in the rows you care about, and then do direct assignment
import torch

y = torch.rand(3, 2, 2)
z = torch.rand(3, 2, 2)
x = torch.rand(3)
mask = x.ge(0.5)

# get row indices
indices = mask.nonzero().squeeze(1)

y[indices] = z[indices]