I have an array of values as well as another array which I would like to create an index to. For example:
value_list = np.array([[2,2,3],[255,243,198],[2,2,3],[50,35,3]])
key_list = np.array([[2,2,3],[255,243,198],[50,35,3]])
MagicFunction(value_list,key_list)
#result = [[0,1,0,2]] which has the same length as value_list
The solutions I have seen online after researching are not quite what I am asking for I believe, any help would be appreciated! I have this brute force code which provides the result but I don't even want to test it on my actual data size
T = np.zeros((len(value_list)), dtype = np.uint32)
for i in range(len(value_list)):
for j in range(len(key_list)):
if sum(value_list[i] == key_list[j]) == 3:
T[i] = j
sum(value_list[i] == key_list[j]) == 3, it would be better to do(value_list[i] == key_list[j]).all(). This both generalizes to any size, not just 3, and it makes it clearer what the code's function is. You could also addbreakafterT[i] = jto save yourself some time.