What would be most elegant and efficient way to find the index of a row in a Numpy 2d array maximizing some function? In particular, I need to find the row with maximal dot product with a given vector. Say, I have
a = np.array([[1, 2, 3], [3, 2, 1]])
b = np.array([6, 5, 4])
Then the result should be 1 since np.dot(a[1],b) is greater than np.dot(a[0],b).
simply:
>>> np.argmax(a.dot(b))
1
np.argmax docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With