1

Im trying to combine following two np.arrays into a single array:

prediction_score =
[0.99764085 0.26231623 0.07232302]

prediction_boxes =
[[282.25906   79.13187  420.98575  226.11221 ]
 [109.91688   94.8121   333.07764  225.87985 ]
 [340.3894    96.612015 601.4172   231.13196 ]]

The combination array must look like this [[i, pred, boxes],...]:

prediction_boxes =
[[1 0.99764085 282.25906   79.13187  420.98575  226.11221 ]
 [1 0.26231623 109.91688   94.8121   333.07764  225.87985 ]
 [1 0.07232302 340.3894    96.612015 601.4172   231.13196 ]]

I tried doing it this way, but it unfortunately didn't work:

import numpy as np

i=1

for x in range(len(pred_scores)):
    np.insert(pred_bboxes[x], 0, pred_scores[x])
    np.insert(pred_bboxes[x], 0, i)
print(pred_bboxes)

Is there a way to do this? I tried other means but those tries were even worse.

3 Answers 3

1

Try hstack:

np.hstack(([[1]]*len(pred_boxes),     # classes
           pred_scores[...,None],     # scores
           pred_boxes)                # boxes
         )
Sign up to request clarification or add additional context in comments.

Comments

1

Numpy's concatenate function deals with this nicely. Try something like:

output = np.concatanate((prediction_score.T, prediction_boxes), axis = 1)

Comments

1

This should work: np.c_[prediction_score,prediction_boxes]

Comments

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.