Hi everyone,
I was wondering if there is a function in Mata that does the opposite of vec(), taking the number of columns as an argument. Consider the following example
You can see that neither colshape() nor rowshape() return the original matrix. I have found the following workaround by transposing the vector into a row one and using rowshape:
But I was wondering if there was direct way. If not, this workaround could be the base for a built-in method invvec(), please?
I was wondering if there is a function in Mata that does the opposite of vec(), taking the number of columns as an argument. Consider the following example
Code:
: A = 1 , 4 \ 2 , 5 \ 3 , 6 : A 1 2 +---------+ 1 | 1 4 | 2 | 2 5 | 3 | 3 6 | +---------+ : vec(A) 1 +-----+ 1 | 1 | 2 | 2 | 3 | 3 | 4 | 4 | 5 | 5 | 6 | 6 | +-----+ : colshape(vec(A),2) 1 2 +---------+ 1 | 1 2 | 2 | 3 4 | 3 | 5 6 | +---------+ : rowshape(vec(A),3) 1 2 +---------+ 1 | 1 2 | 2 | 3 4 | 3 | 5 6 | +---------+
Code:
: a = vec(A)' : rowshape(a,2)' 1 2 +---------+ 1 | 1 4 | 2 | 2 5 | 3 | 3 6 | +---------+
Comment