How can be created a column vector by appending the columns/rows of an array?

How can be created a column vector by appending the columns/rows of an array?

1 Answer



0



Matrix case
You can turn a matrix in GAUSS into a column vector with either vec or vecr. The vec function will append each of the columns of a matrix in to one column vector, like this:

x = { 1 2 3,
      4 5 6,
      7 8 9 };

vec_1 = vec(x);

will set vec_1 equal to:

1
4
7
2
5
8
3
6
9

vecr will create a vector by concatenating the rows of the input matrix and then transposing it into a column vector. For example:

x = { 1 2 3,
      4 5 6,
      7 8 9 };

vec_2 = vecr(x);

will set vec_2 equal to:

1
2
3
4
5
6
7
8
9

N-dimensional array case
You can reshape a GAUSS N-dimensional array into a vector with the vecr function. For example:

dims = { 2, 3, 4 };
a = areshape(seqa(1, 1, 24), dims);

will create the 2x3x4 dimensional array with the following contents:

Plane [1,.,.] 

    1     2     3     4 
    5     6     7     8 
    9    10    11    12 

Plane [2,.,.] 

   13    14    15    16 
   17    18    19    20 
   21    22    23    24

Continuing the example:

v = vecr(a);

will create the column vector, v equal to:

    1 
    2 
    3 
    4 
    5 
    6 
    7 
    8 
    9 
   10 
   11 
   12 
   13 
   14 
   15 
   16 
   17 
   18 
   19 
   20 
   21 
   22 
   23 
   24 

aptech

1,773

Your Answer

1 Answer

0

Matrix case
You can turn a matrix in GAUSS into a column vector with either vec or vecr. The vec function will append each of the columns of a matrix in to one column vector, like this:

x = { 1 2 3,
      4 5 6,
      7 8 9 };

vec_1 = vec(x);

will set vec_1 equal to:

1
4
7
2
5
8
3
6
9

vecr will create a vector by concatenating the rows of the input matrix and then transposing it into a column vector. For example:

x = { 1 2 3,
      4 5 6,
      7 8 9 };

vec_2 = vecr(x);

will set vec_2 equal to:

1
2
3
4
5
6
7
8
9

N-dimensional array case
You can reshape a GAUSS N-dimensional array into a vector with the vecr function. For example:

dims = { 2, 3, 4 };
a = areshape(seqa(1, 1, 24), dims);

will create the 2x3x4 dimensional array with the following contents:

Plane [1,.,.] 

    1     2     3     4 
    5     6     7     8 
    9    10    11    12 

Plane [2,.,.] 

   13    14    15    16 
   17    18    19    20 
   21    22    23    24

Continuing the example:

v = vecr(a);

will create the column vector, v equal to:

    1 
    2 
    3 
    4 
    5 
    6 
    7 
    8 
    9 
   10 
   11 
   12 
   13 
   14 
   15 
   16 
   17 
   18 
   19 
   20 
   21 
   22 
   23 
   24 

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.