Reputation: 15367
I have a numpy array a: [True, False, True, False, False, ...] And I like to have a numpy array that has the indices of the True and False values, i.e. [0, 2, ...] and [1, 3, 4, ...]
Upvotes: 2
Views: 2582
Reputation: 602575
To get the indices of the True
values in a
, you can use
a.nonzero()
For the indices of the False
values, use
(~a).nonzero()
Upvotes: 9