Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a n*1 matrix to a n*n diagonal matrix

Tags:

r

matrix

I have a nx1 matrix I want to convert this to a nxn diagonal matrix in R

matrix transformation

like image 434
bison2178 Avatar asked Dec 25 '13 23:12

bison2178


People also ask

Can a 1x1 matrix be diagonal?

Yes, every 1×1 matrix is diagonal.

How do you convert a column vector to a diagonal matrix?

To convert a vector into a diagonal matrix in R, we can use diag function along with matrix function and use ncol argument where we can put the number of columns equal to the number of values in the vector.


1 Answers

If you just want to know how to do this in R, it's:

my.matrix       <- matrix(0, nrow=4, ncol=4)
diag(my.matrix) <- rep(0.25, 4)
like image 137
gung - Reinstate Monica Avatar answered Oct 06 '22 10:10

gung - Reinstate Monica