0

I want to find the mapping given two arrays A and B, which are permutations of each other. An equivalent function would be

import numpy as np
def perm_map(A, B):
    return [np.where(np.array(B) == el)[0][0] for el in A]

print( perm_map(['A', 'B', 'C'], ['B', 'C', 'A']) )

result for this example is [2, 0, 1]

Questions:

  • Am I calling it correctly?
  • Is there a built-in efficient function for this?
Aleksejs Fomins
  • 688
  • 1
  • 8
  • 20
  • The answers on the above link provide this exact same result without the need for a list comprehension or loops of any sort. It's quicker too : ) – Newskooler Nov 20 '19 at 13:04
  • In my opinion the best answer in above link is by hermidalc. I have also tested a popular answer by RomanS and it does not work – Aleksejs Fomins Nov 20 '19 at 13:07

0 Answers0