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, the vectorization 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 ...
is a
linear transformation which converts the matrix into a
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, ...
. Specifically, the vectorization of a matrix ''A'', denoted vec(''A''), is the column vector obtained by stacking the columns of the matrix ''A'' on top of one another:
:
Here,
represents
and the superscript
denotes the
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 ...
. Vectorization expresses, through coordinates, the
isomorphism
In mathematics, an isomorphism is a structure-preserving mapping between two structures of the same type that can be reversed by an inverse mapping. Two mathematical structures are isomorphic if an isomorphism exists between them. The word i ...
between these (i.e., of matrices and vectors) as vector spaces.
For example, for the 2×2 matrix
, the vectorization is
.

The connection between the vectorization of ''A'' and the vectorization of its transpose is given by the
commutation matrix.
Compatibility with Kronecker products
The vectorization is frequently used together with the
Kronecker product to express
matrix multiplication
In mathematics, particularly in linear algebra, matrix multiplication is a binary operation that produces a matrix from two matrices. For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the ...
as a linear transformation on matrices. In particular,
:
for matrices ''A'', ''B'', and ''C'' of dimensions ''k''×''l'', ''l''×''m'', and ''m''×''n''. For example, if
(the
adjoint endomorphism of the
Lie algebra
In mathematics, a Lie algebra (pronounced ) is a vector space \mathfrak g together with an operation called the Lie bracket, an alternating bilinear map \mathfrak g \times \mathfrak g \rightarrow \mathfrak g, that satisfies the Jacobi iden ...
of all ''n''×''n'' matrices with
complex entries), then
, where
is the ''n''×''n''
identity matrix
In linear algebra, the identity matrix of size n is the n\times n square matrix with ones on the main diagonal and zeros elsewhere.
Terminology and notation
The identity matrix is often denoted by I_n, or simply by I if the size is immaterial ...
.
There are two other useful formulations:
:
:
More generally, it has been shown that vectorization is a
self-adjunction in the monoidal closed structure of any category of matrices.
Compatibility with Hadamard products
Vectorization is an
algebra homomorphism from the space of matrices with the
Hadamard (entrywise) product to C
''n''2 with its Hadamard product:
:
Compatibility with inner products
Vectorization is a
unitary transformation from the space of ''n''×''n'' matrices with the
Frobenius (or
Hilbert–Schmidt)
inner product to C
''n''2 :
:
where the superscript
T denotes the
conjugate transpose
In mathematics, the conjugate transpose, also known as the Hermitian transpose, of an m \times n complex matrix \boldsymbol is an n \times m matrix obtained by transposing \boldsymbol and applying complex conjugate on each entry (the complex c ...
.
Vectorization as a linear sum
The matrix vectorization operation can be written in terms of a linear sum. Let X be an matrix that we want to vectorize, and let e
''i'' be the ''i''-th canonical basis vector for the ''n''-dimensional space, that is
. Let B
''i'' be a block matrix defined as follows:
B
''i'' consists of ''n'' block matrices of size , stacked column-wise, and all these matrices are all-zero except for the ''i''-th one, which is a identity matrix I
''m''.
Then the vectorized version of X can be expressed as follows:
:
Multiplication of X by e
''i'' extracts the ''i''-th column, while multiplication by B
''i'' puts it into the desired position in the final vector.
Alternatively, the linear sum can be expressed using the
Kronecker product:
:
Half-vectorization
For a
symmetric matrix
In linear algebra, a symmetric matrix is a square matrix that is equal to its transpose. Formally,
Because equal matrices have equal dimensions, only square matrices can be symmetric.
The entries of a symmetric matrix are symmetric with ...
''A'', the vector vec(''A'') contains more information than is strictly necessary, since the matrix is completely determined by the symmetry together with the
lower triangular portion, that is, the entries on and below the
main diagonal. For such matrices, the half-vectorization is sometimes more useful than the vectorization. The half-vectorization, vech(''A''), of a symmetric ''n'' × ''n'' matrix ''A'' is the column vector obtained by vectorizing only the lower triangular part of ''A'':
:
For example, for the 2×2 matrix
, the half-vectorization is
.
There exist unique matrices transforming the half-vectorization of a matrix to its vectorization and vice versa called, respectively, the
duplication matrix and the
elimination matrix.
Programming language
Programming languages that implement matrices may have easy means for vectorization.
In
Matlab
MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
/
GNU Octave a matrix
A
can be vectorized by
A(:)
.
GNU Octave also allows vectorization and half-vectorization with
vec(A)
and
vech(A)
respectively.
Julia has the
vec(A)
function as well.
In
Python NumPy arrays implement the
flatten
method, while in
R the desired effect can be achieved via the
c()
or
as.vector()
functions. In
R, function
vec()
of package 'ks' allows vectorization and function
vech()
implemented in both packages 'ks' and 'sn' allows half-vectorization.
Notes
:1.The identity for row-major vectorization is
.
See also
*
Voigt notation
*
Packed storage matrix
A packed storage matrix, also known as packed matrix, is a term used in programming for representing an m\times n matrix
Matrix most commonly refers to:
* ''The Matrix'' (franchise), an American media franchise
** ''The Matrix'', a 1999 scie ...
*
Column-major order
*
Matricization
In multilinear algebra, a reshaping of tensors is any bijection between the set of indices of an order-d tensor and the set of indices of an order-\ell tensor, where \ell refers to the set \ of the first positive integers.
For each integer k wh ...
References
*Jan R. Magnus and Heinz Neudecker (1999), ''Matrix Differential Calculus with Applications in Statistics and Econometrics'', 2nd Ed., Wiley. {{isbn, 0-471-98633-X.
Linear algebra
Matrices