如标题所示,索引具有(n,)
布尔ndarray
ar
且len(l) == ar.shape[0]
的list
l
的最有效方法是什么?
Ok, let's make a list of idioms you could try. Time them you'll have to do yourself, because it will depend on the sizes and also the sparsity of ar
, cf. @Imanol Luengo's comment
np.array(l)[ar] # output is an array
[e for e,m in zip(l, ar) if m]
[l[i] for i in np.where(ar)[0]]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.