I'm trying to figure out the best way of doing this, ideally in Octave, but I'll take NumPy at a pinch.
Let's say I have an axb matrix M. If I want the row indices of the maximum value in any given column, [x, xi] = max(M)
will return these indices for me as a row vector.
For example, if M is:
1 3 5
2 9 1
7 2 4
The above will return row vector [3 2 1]
as xi
; A vector of the indices of each row which contains the maximum value for that column. This is good. I want this row vector.
But what if I want the top n such row vectors?
[edited to explain this better]
For the above example, the first such vector would be the above [3, 2, 1]
, (the indices of the rows with the highest values for each given column). The second such vector would be [2 1 3]
, (the indices of the rows with the second-highest values for each column).
I could do it iteratively, but my actual matrices have many thousands of rows, so this would be quite computationally expensive. I can't find any obvious matrix utility function to help me achieve this. Any suggestions?