简体   繁体   English

查找其值为true的布尔数组的索引

[英]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.

相关问题 Python Boolean 数组设置索引值为 True 为 0 - Python Boolean array set index value of True to 0 替换熊猫数据框x; 如果布尔数组中的各个索引为True,则y值为NaN - Replace pandas dataframe x; y values with NaN if respective index in boolean array is True 在一行中没有所有True值的布尔数组 - Boolean array with no all True values in one row 如何使用布尔型方形对称 numpy 数组中的 True 值存储存储索引对? - How can I store store index pairs using True values from a boolean-like square symmetric numpy array? 如何将数组更改为 boolean 值,使数组 output True/False - How to change an array to boolean values making the array output True/False 具有固定数量的True和False值的随机布尔数组 - Random boolean array with fixed number of True and False values 将 Boolean 数组(即 True False)转换为实际值? - Converting Boolean array (i.e True False) into actual values? 从 Boolean 数组中提取连续的 True 值,同时保留索引 - Extracting consecutive True values from Boolean array, while keeping indices Python/Numpy/Boolean 索引:在具有 N 个连续 True 值的位置修改布尔数组 - Python/Numpy/Boolean Indexing: Modify boolean array at locations with N consecutive True values 如何在大 Pandas DataFrame 中找到“True”值对应的索引和列? - How to find the `True` values' corresponding index and column in a large Pandas DataFrame?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM