I am wondering whats the best way to find all the indices of a Boolean
array, of which the values are True
. For example, an array of bool
values,
import numpy as np
A = np.array([True, False, True, False, True])
true_list = A[A == True].index.tolist()
This will do it easily:
np.where(A)
Or:
A.nonzero()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With