How can I make torch tensor?
I want to make a torch tensor composed of only 1 or -1.
I just try to use torch.empty() and torch.randn().
tmp = torch.randint(low=0, high=2, size=(4, 4))
tmp[tmp==0] = -1
tmp
&gt;&gt; tensor([[ 1, -1, -1,  1],
           [-1,  1,  1, -1],
           [-1, -1,  1,  1],
           [-1,  1, -1,  1]])

However, I don`t know what method is most efficient in time.
And I want to make this code to one line as possible because this code is positioned at __init__ ()

Why not:
tmp = -1 + 2 * torch.randint(low=0, high=2, size=(4, 4))

