You can achieve this by using a boolean mask rather than your numeric mask (PyTorch, NumPy, etc implements different behaviors depending on the data type in the arrays). For your example you would have to do
import torch 

a = torch.arange(3*4).reshape(3,4)
b = torch.zeros(5,4, dtype=torch.long)
mask = torch.tensor([1,0,1,0,1])
b[mask.bool()] = a
print(b)
# tensor([[ 0,  1,  2,  3],
#         [ 0,  0,  0,  0],
#         [ 4,  5,  6,  7],
#         [ 0,  0,  0,  0],
#         [ 8,  9, 10, 11]])