# Recognising degenerate maxima in a matrix

Say I have the following matrix

$\left( \begin{array}{cccccc} 1. & 0 & 0 & 0 & 0 & 0 \\ 0 & 0.707107 & 0 & 0 & 0 & 0.707107 \\ 0 & 0.707107 & 0 & 0 & 0 & 0.707107 \\ 0 & 0 & 0.707107 & 0 & 0.707107 & 0 \\ 0 & 0 & 0.707107 & 0 & 0.707107 & 0 \\ 0 & 0 & 0 & 1. & 0 & 0 \\ \end{array} \right)$

In code this would be

{{1., 0, 0, 0, 0, 0}, {0, 0.707107, 0, 0, 0, 0.707107}, {0, 0.707107,
0, 0, 0, 0.707107}, {0, 0, 0.707107, 0, 0.707107, 0}, {0, 0,
0.707107, 0, 0.707107, 0}, {0, 0, 0, 1., 0, 0}}


Now, what I'm looking for is a way to create a vector of what the index is of the maximum of each row. So for the first row this would be 1, but for the second two and six are both the maximum. The same issue occurs on the third row. What I'd like is that the vector generated by this matrix would be {1,2,6,3,5,4} (although {1,6,2,5,3,4} also works). In words, it should look for the index of the maximal item of each row, but if a maximum has already been found at that index, it should use the index of the other, degenerate, maximum.

Now, personally, I think this is probably not possible. I can't think of where to even start with this, but I figured I might as well get a second opinion on the feasibility. The way I'm doing it now is just creating the vector manually from the above matrix, but this is very tedious as I need to generate many of these matrices for different parameter values.

Perhaps not important to the question, but some background: what I'm doing is taking eigenvectors of a translation invariant system from real space to k-space, and then looking for the k-value that maximizes the transform. This in turn allows me to construct the dispersion curve of my system. Now, due to the translation invariance and having equal parameter values of all components of my system, there are degeneracies, which is expected physically. However, later I investigate what happens when the translation invariance is broken at different sites, which lifts some of the degeneracies while leaving others in place.

• Does DeleteDuplicates[Flatten[Position[#, Max[#]] & /@ matrix]] suit your needs? Jun 7, 2015 at 16:31
• Does indeed seem to do the trick! Jun 7, 2015 at 16:46
• Okay, would you mind answering your question, please? Jun 7, 2015 at 17:21

DeleteDuplicates[Flatten[Position[#, Max[#]] & /@ matrix]]