Commutation matrix
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 is the nm × mn permutation matrix which, for any m × n matrix A, transforms vec into vec:
Here vec is the mn × 1 column vector obtain by stacking the columns of A on top of one another:
where A = . In other words, vec is the vector obtained by vectorizing A in column-major order. Similarly, vec is the vector obtaining by vectorizing A in row-major order. The cycles and other properties of this permutation have been heavily studied for in-place matrix transposition algorithms.
In the context of quantum information theory, the commutation matrix is sometimes referred to as the swap matrix or swap operator
Properties
- The commutation matrix is a special type of permutation matrix, and is therefore orthogonal. In particular, K is equal to, where is the permutation over for which
- The determinant of K is.
- Replacing A with AT in the definition of the commutation matrix shows that Therefore, in the special case of m = n the commutation matrix is an involution and symmetric.
- The main use of the commutation matrix, and the source of its name, is to commute the Kronecker product: for every m × n matrix A and every r × q matrix B,
- The case of n=q=1 for the above equation states that for any column vectors v,w of sizes m,r respectively,
- Two explicit forms for the commutation matrix are as follows: if er,''j denotes the j''-th canonical vector of dimension r then
- The commutation matrix may be expressed as the following block matrix:
Code
For both square and rectangular matrices ofm rows and n columns, the commutation matrix can be generated by the code below.Python
import numpy as np
def comm_mat:
# determine permutation applied by K
w = np.arange.reshape.T.ravel
# apply this permutation to the rows of identity matrix and return result
return np.eye
Alternatively, a version without imports:
def delta:
return int
def comm_mat:
# determine permutation applied by K
v =
# apply this permutation to the rows of identity matrix
I = delta for j in range] for i in range]
return for i in v]
MATLAB
function P = com_mat
% determine permutation applied by K
A = reshape;
v = reshape;
% apply this permutation to the rows of identity matrix
P = eye;
P = P;
R
- Sparse matrix version
Example
Let denote the following matrix:has the following column-major and row-major vectorizations :
The associated commutation matrix is
. As expected, the following holds: