I'm dealing with correlation matrices and I want to rearrange the rows and columns so that the column with the highest average correlation is in the middle, the second best is one index above that, the third is one index below the middle, and so on and so forth.
In an example, this is the original matrix
[[ 1. , -0.85240671, 0.93335528, 0.75431679, 0.81586527],
[-0.85240671, 1. , -0.874545 , -0.68551567, -0.8594703 ],
[ 0.93335528, -0.874545 , 1. , 0.7103762 , 0.86104527],
[ 0.75431679, -0.68551567, 0.7103762 , 1. , 0.73345121],
[ 0.81586527, -0.8594703 , 0.86104527, 0.73345121, 1. ]]
Ideally the new column/row order (using python indexing) is 3, 1, 2, 0, 4. So it would look like
[[1,-.686,.710,.754,.733],
[-.686,1,-.875,-.852,-.859],
[.710,-.875,1,.933,.861],
[.754,-.852,.754,1,.816],
[.733,-.859,.861,.816,1]]
None of the sorting algorithms I know seem to be able to deal with my goal of "symmetry". I'm using numpy for my matrices.
Some of the matrices will not have odd dimensions so I also want a way to deal with matrices with even numbers for their dimensions if possible. Any help would be awesome.