find the index of a boolean array whose values are true
19,198
This will do it easily:
np.where(A)
Or:
A.nonzero()
Author by
daiyue
Updated on June 18, 2022Comments
-
daiyue almost 2 years
I am wondering whats the best way to find all the indices of a
Boolean
array, of which the values areTrue
. For example, an array ofbool
values,import numpy as np A = np.array([True, False, True, False, True]) true_list = A[A == True].index.tolist()