0

I'm having troubles with the simple task of slicing an array based on another array's values.

I have the array scores, with shape:

scores.shape = (1, 100, 1)

providing confidence scores for 100 detections in every image in a batch (but I'm using a single image, so I only have one element in the batch). So, for the first and only image, I have values for 100 detection::

scores[0] -> [score00, ..., score99]

Then, I have another similar array, bboxes...for each image in the batch (again, using only one image), and for all the 100 detections in each image, it contains 4 values. So the shape is:

bboxes.shape = (1, 100, 4)

For the only image, I have 100 quadruples of values

bboxes[0] -> [ [x_min, y_min, x_max, y_max], ..., [x_min, y_min, x_max, y_max] ]

and, out of these 100 quadruples, I need to extract only those corresponding to the elements in scores whose value is higher than a certain threshold (0.5). So, say that only the first 2 scores are higher than the threshold, I would want only the first 2 quadruples.

I'm trying something like:

print(bboxes[0][scores[0]>0.5])

but I'm getting the error:

IndexError: boolean index did not match indexed array along dimension 1; dimension is 4 but corresponding boolean dimension is 1

What am I doing wrong?

1
  • scores[0]>0.5 is a boolean... Commented Feb 3, 2020 at 13:32

1 Answer 1

1

Try this:

for score, box in zip(scores[0], bboxes[0]):
    if score > 0.5:
        print(box)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it works, thank you very much! Honestly, I didn't try this way because I was trying to figure out to get the values without using for loops, but I didn't manage to do it yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.