How to change a vector to zero-one vector

I have a vector such as [0.1, 0.2, 0.6, 0.3]. I want to change it to [0, 0, 1, 0] by the method of if value >= 0.5 then value = 1, else value = 0. Is there a convenient function?
Thank you very much!

a = torch.Tensor([0.1, 0.2, 0.6, 0.3])
b = (a >= 0.5)

I think this would work, if you need a variable instead of a tensor, you may use:

a = Variable(torch.Tensor([0.1, 0.2, 0.6, 0.3]))
b = (a >= 0.5)

Thank you very much! I just found it.