You have to be a bit careful with the types (byte does not have negative numbers, so I added .float() below, .long() would also work if you wanted integers), but then the expression notation should work fine:
a = torch.rand(2,2)
print(2*(a>0.5).float()-1)

Best regards
Thomas