I don’t think there is a proper way to avoid the for loop, since you are sequentially overwriting out in:
outp[m] = inp[m]

I.e. outp and inp have a shape of [3, 4] while you are creating num_masks with the same shape.
In the first iteration the first mask would thus manipulate outp, in the second iteration this already changed outp tensor would then be again manipulated so you have a sequential dependency.
One potential way would be to “sum” all masks to a single one and perform this operation only once.
out = torch.zeros(inp.shape)
mask = masks.sum(dim=0).bool()
out[mask] = inp[mask]
out == outp

but it depends on your use case and if that’s really what you are trying to achieve.