In mathematics, especially in linear algebra and matrix theory, the vectorization of a matrix is a linear transformation which converts the matrix into a column vector. Specifically, the vectorization of a matrix A, denoted vec, is the column vector obtained by stacking the columns of the matrix Aon top of one another: Here, represents and the superscript denotes the transpose. Vectorization expresses, through coordinates, the isomorphism between these as vector spaces. For example, for the 2×2 matrix =, the vectorization is.
Compatibility with Kronecker products
The vectorization is frequently used together with the Kronecker product to express matrix multiplication 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 , then, where is the n×nidentity matrix. 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.
The matrix vectorization operation can be written in terms of a linear sum. Let X be an matrix that we want to vectorize, and letei be the i-th canonical basis vector for the n-dimensional space, that is. Let Bi be a block matrix defined as follows: Bi consists of nblock matrices of size, stacked column-wise, and all these matrices are all-zero except for the i-th one, which is a identity matrix Im. Then the vectorized version of X can be expressed as follows: Multiplication of X by ei extracts the i-th column, while multiplication by Bi 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 matrixA, the vector vec 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, of a symmetricn × n matrix A is the column vector obtained by vectorizing only the lower triangular part of A: For example, for the 2×2 matrix A =, the half-vectorization is vech =. 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/GNU Octave a matrix A can be vectorized by A. GNU Octave also allows vectorization and half-vectorization with vec and vech respectively. Julia has the vec function as well. In PythonNumPy 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.