SHAPECOL Function

SHAPECOL (matrix, nrow <, ncol> <, pad-value> ) ;

The SHAPECOL function reshapes and repeats values in a matrix. It is similar to the SHAPE function except that the SHAPECOL function produces the result matrix by traversing the argument matrix in column-major order.

The following statements demonstrate the SHAPECOL function:

A = {1 2 3, 4 5 6};
c = shapecol(A, 3);
v = shapecol(A, 0, 1);
print c v;

Figure 23.319: Reshaped Matrices

c   v
1 5 1
4 3 4
2 6 2
    5
    3
    6


The vector v in the example is called the vec of $\mb {A}$ and is written $\mbox{vec}(\mb {A})$. Uses of the $\mbox{vec}$ operator in matrix algebra are described in Harville (1997). One important property is the relationship between the $\mbox{vec}$ operator and the Kronecker product. If $\mb {A}$, $\mb {B}$, and $\mb {X}$ have the appropriate dimensions, then

\[  \mbox{vec}(\mb {A}\mb {X}\mb {B}) = (\mb {B}^\prime \otimes \mb {A})\mbox{vec}(\mb {X})  \]

There is also a relationship between the SHAPECOL function and the SHAPE function. If $\mb {A}$ is a matrix, then the following two computations are equivalent:

b = shapecol(A, m, n, padVal);
c = T(shape(A`, n, m, padVal));

See the VECH function for a similar function that is useful for computing with symmetric matrices.