In
mathematics, especially in
linear algebra
Linear algebra is the branch of mathematics concerning linear equations such as:
:a_1x_1+\cdots +a_nx_n=b,
linear maps such as:
:(x_1, \ldots, x_n) \mapsto a_1x_1+\cdots +a_nx_n,
and their representations in vector spaces and through matric ...
and
matrix theory
In mathematics, a matrix (plural matrices) is a rectangular array or table of numbers, symbols, or expressions, arranged in rows and columns, which is used to represent a mathematical object or a property of such an object.
For example,
\beg ...
, the commutation matrix is used for transforming the
vectorized form of a
matrix
Matrix most commonly refers to:
* ''The Matrix'' (franchise), an American media franchise
** '' The Matrix'', a 1999 science-fiction action film
** "The Matrix", a fictional setting, a virtual reality environment, within ''The Matrix'' (franchi ...
into the vectorized form of its
transpose
In linear algebra, the transpose of a matrix is an operator which flips a matrix over its diagonal;
that is, it switches the row and column indices of the matrix by producing another matrix, often denoted by (among other notations).
The tr ...
. Specifically, the commutation matrix K
(''m'',''n'') is the ''nm'' × ''mn'' matrix which, for any ''m'' × ''n'' matrix A, transforms vec(A) into vec(A
T):
:K
(''m'',''n'') vec(A) = vec(A
T) .
Here vec(A) is the ''mn'' × 1
column vector
In linear algebra, a column vector with m elements is an m \times 1 matrix consisting of a single column of m entries, for example,
\boldsymbol = \begin x_1 \\ x_2 \\ \vdots \\ x_m \end.
Similarly, a row vector is a 1 \times n matrix for some n, ...
obtain by stacking the columns of A on top of one another:
:
where A =
''i'',''j''">''A''i'',''j'' In other words, vec(A) is the vector obtained by vectorizing A in
column-major order. Similarly, vec(A
T) is the vector obtaining by vectorizing A in row-major order.
In the context of
quantum information theory
Quantum information is the information of the state of a quantum system. It is the basic entity of study in quantum information theory, and can be manipulated using quantum information processing techniques. Quantum information refers to both ...
, 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
In mathematics, particularly in matrix theory, a permutation matrix is a square binary matrix that has exactly one entry of 1 in each row and each column and 0s elsewhere. Each such matrix, say , represents a permutation of elements and, wh ...
, and is therefore
orthogonal
In mathematics, orthogonality is the generalization of the geometric notion of '' perpendicularity''.
By extension, orthogonality is also used to refer to the separation of specific features of a system. The term also has specialized meanings in ...
. In particular, K
(''m'',''n'') is equal to
, where
is the permutation over
for which
::
* Replacing A with A
T 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
Symmetry (from grc, συμμετρία "agreement in dimensions, due proportion, arrangement") in everyday language refers to a sense of harmonious and beautiful proportion and balance. In mathematics, "symmetry" has a more precise definit ...
.
* The main use of the commutation matrix, and the source of its name, is to commute the
Kronecker product
In mathematics, the Kronecker product, sometimes denoted by ⊗, is an operation
Operation or Operations may refer to:
Arts, entertainment and media
* ''Operation'' (game), a battery-operated board game that challenges dexterity
* Oper ...
: for every ''m'' × ''n'' matrix A and every ''r'' × ''q'' matrix B,
::
:This property is often used in developing the higher order statistics of Wishart covariance matrices.
* The case of ''n=q=1'' for the above equation states that for any column vectors v,w of sizes ''m,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: if e
''r'',''j'' denotes the ''j''-th canonical vector of dimension ''r'' (i.e. the vector with 1 in the ''j''-th coordinate and 0 elsewhere) then
::
* The commutation matrix may be expressed as the following block matrix:
::
:Where the ''p,q'' entry of ''n x m'' block-matrix K
''i,j'' is given by
::
:For example,
::
Code
For both square and rectangular matrices of
m
rows and
n
columns, the commutation matrix can be generated by the code below.
Python
import numpy as np
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) , :
Alternatively, a version without imports:
# Kronecker delta
def delta(i, j):
return int(i j)
def comm_mat(m, n):
# determine permutation applied by K
v = * 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 [ifor i in v">[i.html" ;"title="[i">[ifor i in v
MATLAB
function P = com_mat(m, n)
% determine permutation applied by K
A = reshape(1:m*n, m, n);
v = reshape(A', 1, []);
% apply this permutation to the rows (i.e. to each column) of identity matrix
P = eye(m*n);
P = P(v,:);
Example
Let
denote the following
matrix:
:
has the following column-major and row-major vectorizations (respectively):
:
The associated commutation matrix is
:
(where each
denotes a zero). As expected, the following holds:
:
:
References
* Jan R. Magnus and Heinz Neudecker (1988), ''Matrix Differential Calculus with Applications in Statistics and Econometrics'', Wiley.
{{Matrix classes
Linear algebra
Matrices
Articles with example Python (programming language) code
Articles with example MATLAB/Octave code