Why do I get a sparse matrix?

Diagonal is a kind of sparse matrix. You can write collect(Diagonal(...)) to get a normal matrix, or better just use diagm.

1 Like