This code should work:
a = torch.arange(3*2*2).view(1, 3, 2, 2)
val, idx = a.max(1, keepdim=True)
z = torch.zeros_like(a)
z[torch.arange(z.size(0))[:, None], idx] = val
print(z)
> tensor([[[[ 0,  0],
            [ 0,  0]],

           [[ 0,  0],
            [ 0,  0]],

           [[ 8,  9],
            [10, 11]]]])