This only works if the condition of the where statement means that the result is not evaluated False. But then it’s easy:
import numpy as np a = np.random.randint(1,11,100) a_5 = a[np.where(a>5)] a_10 = a[np.where(a>10)] a_5.any() #True a_10.any() #False
So, if you want, you can try this before assigning, of course:
a[np.where(a>5)].any() #True a[np.where(a>10)].any() #False
Schuh source share