I have an inefficient algorithm that I need to improve.
Essentially I have arrays:
ids = [134543, ..., 234]
a = [123, ..., 3546]
b = [[435, ..., 549][245, ..., 4986]]
all of the same length (i.e. ids.shape = (600000,) a.shape = (600000,) b.shape = (600000, 2))
and a smaller array of ids of note (length approx 100)
ids_important = [345, ..., 549]
I want to find the indices of the important ids in my ids array, and then output the corresponding elements in a and b.
My current algorithm to do this is:
for i in range(ids_important.shape[0]):
for j in range(ids.shape[0]):
if(ids[j] == ids_important[i]):
print(a[j])
print(b[j,0])
this algorithm is incredibly slow given the size of the array. I've been told I can improve it using masked arrays but haven't been able to work out how to implement that. Help would be very much appreciated.