Optimize loops over labels

Use np.in1d to replace ineffcient list comprehensions