In mathematics, especially in linear algebra and matrix theory, the commutation matrix is used for transforming the vectorized form of a matrix into the vectorized form of its transpose. Specifically, the commutation matrix K(m,n) is the nm × mn matrix which, for any m × n matrix A, transforms vec(A) into vec(AT):
K(m,n) vec(A) = vec(AT) .Here vec(A) is the mn × 1 column vector obtain by stacking the columns of A on top of one another:
\operatorname{vec}(A)=[A1,1,\ldots,Am,1,A1,2,\ldots,Am,2,\ldots,A1,n,\ldots,Am,n]T
In the context of quantum information theory, the commutation matrix is sometimes referred to as the swap matrix or swap operator [1]
P\pi
\pi
\{1,...,mn\}
\pi(i+m(j-1))=j+n(i-1), i=1,...,m, j=1,...,n.
K(r,(A ⊗ B)K(n,=B ⊗ A.
This property is often used in developing the higher order statistics of Wishart covariance matrices.[2]
K(r,m)(v ⊗ w)=w ⊗ v.
This property is the reason that this matrix is referred to as the "swap operator" in the context of quantum information theory.
K(r,=
r | |
\sum | |
i=1 |
m | |
\sum | |
j=1 |
\left(er,i{em,j
K(m,n)=\begin{bmatrix} K1,1& … &K1,n\\ \vdots&\ddots&\vdots\\ Km,1& … &Km,n, \end{bmatrix},
Where the p,q entry of n x m block-matrix Ki,j is given by
Kij(p,q)=\begin{cases} 1&i=qandj=p,\\ 0&otherwise. \end{cases}
For example,
K(3,4)=\left[\begin{array}{ccc|ccc|ccc|ccc} 1&0&0&0&0&0&0&0&0&0&0&0\\ 0&0&0&1&0&0&0&0&0&0&0&0\\ 0&0&0&0&0&0&1&0&0&0&0&0\\ 0&0&0&0&0&0&0&0&0&1&0&0\\ \hline 0&1&0&0&0&0&0&0&0&0&0&0\\ 0&0&0&0&1&0&0&0&0&0&0&0\\ 0&0&0&0&0&0&0&1&0&0&0&0\\ 0&0&0&0&0&0&0&0&0&0&1&0\\ \hline 0&0&1&0&0&0&0&0&0&0&0&0\\ 0&0&0&0&0&1&0&0&0&0&0&0\\ 0&0&0&0&0&0&0&0&1&0&0&0\\ 0&0&0&0&0&0&0&0&0&0&0&1\end{array}\right].
For both square and rectangular matrices of m
rows and n
columns, the commutation matrix can be generated by the code below.
def comm_mat(m, n): # determine permutation applied by K w = np.arange(m * n).reshape((m, n), order="F").T.ravel(order="F")
# apply this permutation to the rows (i.e. to each column) of identity matrix and return result return np.eye(m * n)[w, :]
Alternatively, a version without imports:
def delta(i, j): return int(i
def comm_mat(m, n): # determine permutation applied by K v = [m * j + i for i in range(m) for j in range(n)]
# apply this permutation to the rows (i.e. to each column) of identity matrix I = delta(i, j) for j in range(m * n) for i in range(m * n)] return [I[i] for i in v]
% determine permutation applied by KA = reshape(1:m*n, m, n);v = reshape(A', 1, []);
% apply this permutation to the rows (i.e. to each column) of identity matrixP = eye(m*n);P = P(v,:);
comm_mat = function(m, n)
Let
A
3 x 2
A=\begin{bmatrix}1&4\ 2&5\\ 3&6\\ \end{bmatrix}.
A
vcol=\operatorname{vec}(A)=\begin{bmatrix}1\ 2\\ 3\\ 4\ 5\ 6\ \end{bmatrix}, vrow=\operatorname{vec}(AT)= \begin{bmatrix}1\ 4\\ 2\\ 5\ 3\ 6\ \end{bmatrix}.
The associated commutation matrix is
K=K(3,2)=\begin{bmatrix} 1& ⋅ & ⋅ & ⋅ & ⋅ & ⋅ \\ ⋅ & ⋅ & ⋅ &1& ⋅ & ⋅ \\ ⋅ &1& ⋅ & ⋅ & ⋅ & ⋅ \\ ⋅ & ⋅ & ⋅ & ⋅ &1& ⋅ \\ ⋅ & ⋅ &1& ⋅ & ⋅ & ⋅ \\ ⋅ & ⋅ & ⋅ & ⋅ & ⋅ &1\\ \end{bmatrix},
⋅
KTK=KKT=I6
Kvcol=vrow