Python - 使用另一个数组的数组子集,得到 IndexError
Python - array subset using another array, getting 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个四元组中,我只需要提取scores中值高于某个阈值(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)
我在根据另一个数组的值对数组进行切片这一简单任务时遇到了麻烦。
我有数组 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个四元组中,我只需要提取scores中值高于某个阈值(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)