0

I have a list J1 and a numpy array inv_r. I want to remove elements in inv_r according to indices in J1. I present the current and expected output.

import numpy as np

J1 = [[1, 3, 7, 9, 10]]
inv_r = np.array([[19371.82250346, 20264.94910211, 19697.49114878, 20151.47031158,
                   19899.73292203, 19912.05009437, 19567.94111435, 20777.21170365,
                   19525.03386252, 20375.7252995, 20397.43278826, 19371.82250346]])

inv_rJ1 = [inv_r[0][idx-1] for idx in J1[0]]
print(inv_rJ1)

The current output is

[19371.82250346, 19697.49114878, 19567.94111435, 19525.03386252, 20375.7252995]

The expected output is

[19371.82250346,19697.49114878, 19899.73292203, 19912.05009437, 19567.94111435,19525.03386252, 19371.82250346]

0 Answers0