You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取numpy布尔数组中所有false值对应的索引

解决方案

你只需要对原布尔数组做取反操作后再传入np.where()即可,有两种常用实现写法:

  • 简洁写法(使用numpy按位取反运算符~):
test_false_idx = np.where(~test)[0]
  • 高可读性写法(显式判断值等于False):
test_false_idx = np.where(test == False)[0]

效果验证

使用你提供的测试数组运行验证:

import numpy as np
test = np.array([True, False, True, True])
# 获取所有False值的索引
print(np.where(~test)[0])
# 输出结果:[1]

内容的提问来源于stack exchange,提问作者Melanie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 02:45:08