TITLE: How to rotate the positions of a matrix by 90 degrees
QUESTION [10 upvotes]: I have a 5x5 matrix of values. I'm looking for a simple formula that I can use to rotate the position of the values (not the values themselves) 90 degrees within the matrix.
For example, here is the original matrix:
01 02 03 04 05
06 07 08 09 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

and then when the position of the values are rotated 90 degrees, it would look like this:
21 16 11 06 01
22 17 12 07 02
23 18 13 08 03
24 19 14 09 04
25 20 15 10 05

I found this post and this one, and I'm sure the answer I'm after is in there somewhere, but I've been out of university for quite a few years and am having trouble following the algorithm.
I need this for a C# program I'm writing and will be using Math.Net Numberics. I'm hoping there is just a simple rotation matrix/vector I can use to multiply my matrix with that will give me the result I'm after. Any suggestions are appreciated.

REPLY [11 votes]: Transpose the matrix, then reverse the order of the columns. So $$M\mapsto M^T\begin{bmatrix}0&0&\cdots&0&1\\0&0&\cdots&1&0\\\vdots&\vdots&&\vdots&\vdots\\0&1&\cdots&0&0\\1&0&\cdots&0&0\end{bmatrix}$$
For instance $$\begin{bmatrix}a&b&c\\d&e&f\\g&h&i\end{bmatrix}\mapsto\begin{bmatrix}a&b&c\\d&e&f\\g&h&i\end{bmatrix}^T\begin{bmatrix}0&0&1\\0&1&0\\1&0&0\end{bmatrix}=\begin{bmatrix}a&d&g\\b&e&h\\c&f&i\end{bmatrix}\begin{bmatrix}0&0&1\\0&1&0\\1&0&0\end{bmatrix}=\begin{bmatrix}g&d&a\\h&e&b\\i&f&c\end{bmatrix}$$