I want to create a tensor only containing boolean values. In Matlab that would be
a = false(10,1)
Isn't this more economical (albeit longer):
a = torch.zeros(10, dtype=torch.bool)
or, in older versions,
a = torch.zeros(10, dtype=torch.uint8)
(Thanks @drevicko for the pointer to bool.)
torch.bool type you can (should?) use.torch.where(cond,a,b) will print a deprecated warning if cond is of type ByteTensor. You can conveniently use .type(torch.bool) to avoid the warning: cond.type(torch.bool).Already found it:
a = torch.zeros(10)
b = a.type(torch.ByteTensor)
You can use torch.full to create a tensor with any arbitrary value, including booleans:
torch.full((20, 15), True)
torch.full((20, 15), False)
Or, you can use torch.ones or torch.zeros by specifying the torch.bool data type:
torch.ones((20, 15), dtype=torch.bool) # True
torch.zeros((20, 15), dtype=torch.bool) # False