mask list/tensor with multiple conditions?
The following code masks fine
mask = targets &gt;= 0
targets = targets[mask]

However, when I try masking with two conditions, it gives an error of RuntimeError: Boolean value of Tensor with more than one value is ambiguous
mask = (targets &gt;= 0 and targets &lt;= 5)
targets = targets[mask]

is there a way to do this?

You are making a mistake while using brackets. Bracket around each of the conditions so that NumPy considers them as individual arrays.
targets = np.random.randint(0,10,(10,))

mask = (targets&gt;=0) &amp; (targets&lt;=5) #&lt;----------

print(mask)
targets[mask]

[ True False  True False False  True  True  True False  True]
array([4, 1, 3, 1, 5, 3])


You can create some complex logic using multiple masks and then directly index an array with them. Example - XNOR can be written as ~(mask1 ^ mask2)

