python - Python - 使用另一个数组的数组子集,得到 IndexError
问题描述
我在根据另一个数组的值对数组进行切片的简单任务时遇到了麻烦。
我有数组scores,形状为:
scores.shape = (1, 100, 1)
为批次中的每个图像中的 100 次检测提供置信度分数(但我使用的是单个图像,因此批次中只有一个元素)。因此,对于第一个也是唯一一个图像,我有 100 个检测值::
scores[0] -> [score00, ..., score99]
然后,我有另一个类似的数组bboxes ...对于批次中的每个图像(同样,只使用一个图像),并且对于每个图像中的所有 100 个检测,它包含 4 个值。所以形状是:
bboxes.shape = (1, 100, 4)
对于唯一的图像,我有 100 个四倍的值
bboxes[0] -> [ [x_min, y_min, x_max, y_max], ..., [x_min, y_min, x_max, y_max] ]
并且,在这 100 个四元组中,我只需要提取与分数中值高于某个阈值(0.5)的元素相对应的那些。所以,假设只有前 2 个分数高于阈值,我只想要前 2 个四倍。
我正在尝试类似的东西:
print(bboxes[0][scores[0]>0.5])
但我得到了错误:
IndexError: boolean index did not match indexed array along dimension 1; dimension is 4 but corresponding boolean dimension is 1
我究竟做错了什么?
解决方案
试试这个:
for score, box in zip(scores[0], bboxes[0]):
if score > 0.5:
print(box)
推荐阅读
- git - Git - '你的分支在“X”提交之前是“X”。'
- rust - 为什么 rust 在仅用于测试时会抱怨未使用的功能?
- javascript - 如何修剪字符串返回以使我的测试通过?
- html - 浏览器如何处理重复属性?
- php - 制作特定类型的 json 的问题
- html - 为什么粘性位置不适用于我的导航?
- c# - 有没有办法检测浏览器是否已在 asp.net web mvc 5.0 项目中关闭?
- javascript - 如何找到 Firefox、Chrome、Edge 和 Safari 的可执行路径
- mysql - symfony 中的教义子查询
- excel - 使用 OpenXml 嵌入 Excel 加载项