Chained numerical comparisons in PyTorch
In PyTorch we can do comparisons between elements in tensors like so:
import torch

a = torch.tensor([[1,2], [2,3], [3,4]])
b = torch.tensor([[3,4], [1,2], [2,3]])

print(a.size())
# torch.Size([3, 2])
print(b.size())
# torch.Size([3, 2])

c = a[:, 0] &lt; b[:, 0]

print(c)
# tensor([ True, False, False])

However, when we try to add a condition, the snippet fails:
c = a[:, 0] &lt; b[:, 1] &lt; b[:, 0]

The expected output is
 tensor([ False, False,  False])

So, for each element in a, compare its first element with the second element of the corresponding item in b, and compare that element with the first element of the same item in b.
Traceback (most recent call last):
File &quot;scratch_12.py&quot;, line 9, in 
c = a[:, 0] &lt; b[:, 1] &lt; b[:, 0]
RuntimeError: bool value of Tensor with more than one value is ambiguous
Why is that, and how can we solve it?

You have to separate your condition in two conditions by using directly the &amp; operator. As to why exactly, it's due to the syntax of torch.
c = (a[:, 0] &lt; b[:, 1]) &amp; (b[:, 1] &lt; b[:, 0])

