I have two arrays A and B of the same size. I'd need to get the values and indices of items in the arrays according to B's items. Here is my code:
promotes = [a for a,b in zip(A, B) if b == 1]
demotes = [a for a,b in zip(A, B) if b == 0]
promotes_index = [k for k,(a,b) in enumerate(zip(A, B)) if b == 1]
demotes_index = [k for k,(a,b) in enumerate(zip(A, B)) if b == 0]
I'm sure there is a more efficient way to compute promotes, demotes, and the indices.
In more simple words, if A and promotes are like:
A = array([ 4, 6, 9, 10]))
promotes = array([4, 9])
how could I get promote_index from A and promotes:
promotes_index = array([0, 2])
I appreciate any response.
AandBnp arrays or lists?