Boolean between ByteTensor

I was trying to get a mask from multiple conditions like x > 0.5 and x<1
however, if x is a tensor, current framework doesn’t support it.

What I’m doing now is

(x>0.5 + x<1) == 2

I feel like this would be slower than boolean calculation if there were a boolean calculation.

Is there any other more decent way?

I’d think multiplication is more canonical…

Ok. then what about or.

r = torch.randn(10)
print ((r<-1) | (r>1))

(& also works for and)

Best regards

Thomas

2 Likes