[英]find the index of a boolean array whose values are true
I am wondering whats the best way to find all the indices of a Boolean
array, of which the values are True
. 我想知道什么是找到
Boolean
数组(其值为True
所有索引的最佳方法。 For example, an array of bool
values, 例如,
bool
值数组
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.