Here vec(A) is themn × 1column vector obtain by stacking the columns ofA on top of one another:
whereA = [Ai,j]. In other words, vec(A) is the vector obtained by vectorizingA incolumn-major order. Similarly, vec(AT) is the vector obtaining by vectorizingA in row-major order. Thecycles and other properties of this permutation have been heavily studied forin-place matrix transposition algorithms.
The commutation matrix is a special type ofpermutation matrix, and is thereforeorthogonal. In particular,K(m,n) is equal to, where is the permutation over for which
The determinant ofK(m,n) is.
ReplacingA withAT in the definition of the commutation matrix shows thatK(m,n) = (K(n,m))T. Therefore, in the special case ofm =n the commutation matrix is aninvolution andsymmetric.
The main use of the commutation matrix, and the source of its name, is to commute theKronecker product: for everym ×n matrixA and everyr ×q matrixB,
This property is often used in developing the higher order statistics of Wishart covariance matrices.[2]
The case ofn=q=1 for the above equation states that for any column vectorsv,w of sizesm,r respectively,
This property is the reason that this matrix is referred to as the "swap operator" in the context of quantum information theory.
Two explicit forms for the commutation matrix are as follows: ifer,j denotes thej-th canonical vector of dimensionr (i.e. the vector with 1 in thej-th coordinate and 0 elsewhere) then
The commutation matrix may be expressed as the following block matrix:
Where thep,q entry ofn x m block-matrixKi,j is given by
importnumpyasnpdefcomm_mat(m,n):# determine permutation applied by Kw=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 resultreturnnp.eye(m*n)[w,:]
Alternatively, a version without imports:
# Kronecker deltadefdelta(i,j):returnint(i==j)defcomm_mat(m,n):# determine permutation applied by Kv=[m*j+iforiinrange(m)forjinrange(n)]# apply this permutation to the rows (i.e. to each column) of identity matrixI=[[delta(i,j)forjinrange(m*n)]foriinrange(m*n)]return[I[i]foriinv]
functionP=com_mat(m, n)% 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,:);