I have a numpy matrix:
>>> A = np.matrix('1 2 3; 5 1 6; 9 4 2') >>> A matrix([[1, 2, 3], [5, 1, 6], [9, 4, 2]])
I would like to get the index of the maximum value in each row along with the value itself. I can get indexes for maxima using A.argmax (axis = 1), in which case I would get:
>>> indices = A.argmax(axis=1) >>> indices matrix([[2], [2], [0]])
How can I use an array of 'indices' to get an array of maximum values ββfor each row in the matrix? Is there a way to do this more efficiently or in a single operation? Is there a function that returns values ββalong with their row and column coordinates?
source share