I have a numpy array and corresponding lookup values. From every column of data, I should get maximum position of the corresponding lookup an convert that position into result of data.
I have to do as shown in the picture.
Picture speaks better than my language.
import numpy as np
data = np.array([[0, 2, 1, 4, 3, 2, 4, 4, 1],
[1, 1, 2, 0, 3, 4, 4, 2, 1],
[2, 2, 1, 4, 4, 1, 4, 4, 4]] )
print (data)
print ()
lookup = np.array([[60, 90, 90, 60, 50],
[90, 90, 80, 90, 90],
[60, 40, 90, 60, 50]])
print (lookup)
print ()
I did as follows:
data = data.transpose(1,0)
lookup = lookup.transpose(1,0)
results = []
for d in data:
matches = lookup[d].diagonal()
print (matches)
idx = np.argmax(matches, axis=0)
res = d[idx]
results.append(res)
print ()
print (results)
It worked. But, any better way of doing it?
