Reputation: 129
I feel like this is a really simple question but I can't find the solution.
Given a boolean array of true/false values, I need the output of all the indices with the value "false". I have a way to do this for true:
test = [ True False True True]
test1 = np.where(test)[0]
This returns [0,2,3], in other words the corresponding index for each true value. Now I need to just get the same thing for the false, where the output would be [1]. Anyone know how?
Upvotes: 4
Views: 4743
Reputation: 2082
Using explicite np.array()
.
import numpy as np
test = [True, False, True, True]
a = np.array(test)
test1 = np.where(a==False)[0] #np.where(test)[0]
print(test1)
Upvotes: 1
Reputation: 71562
With enumerate
:
>>> test = [True, False, True, True]
>>> [i for i, b in enumerate(test) if b]
[0, 2, 3]
>>> [i for i, b in enumerate(test) if not b]
[1]
Upvotes: 2