Language Reference


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 25.376: 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 $\bA $" and is written $\mbox{vec}(\bA )$. 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 direct product operator (Kronecker product operator). If $\bA $, $\bB $, and $\bX $ have the appropriate dimensions, then

\[ \mbox{vec}(\bA \bX \bB ) = (\bB ^\prime \otimes \bA )\mbox{vec}(\bX ) \]

There is also a relationship between the SHAPECOL function and the SHAPE function . If $\bA $ 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.