# Why do I get a sparse matrix?

**URL:** <https://discourse.julialang.org/t/why-do-i-get-a-sparse-matrix/61196>\
**Category:** General Usage\
**Tags:** linearalgebra\
**Created:** [May 15, 2021, 11:10am UTC](https://discourse.julialang.org/t/why-do-i-get-a-sparse-matrix/61196 "2021-05-15T11:10:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stla/32/20382_2.png) [@stla](https://discourse.julialang.org/u/stla)\
**Post date:** [May 15, 2021, 11:10am UTC](https://discourse.julialang.org/t/why-do-i-get-a-sparse-matrix/61196/1 "2021-05-15T11:10:01Z")

</div>

Hello,

I have these two matrices:

```julia
julia> L
1×1 Array{Float64,2}:
 3.0

julia> M
2×1 Array{Float64,2}:
 2.0
 1.0

```

I do:

```julia
import LinearAlgebra
d = 3
Ctilde = hcat(vcat(L,M), vcat(zeros(size(L,1),d-size(L,1)), LinearAlgebra.Diagonal(ones(d-size(L,1)))))

```

Then my matrix `Ctilde` is a sparse matrix:

```julia
julia> Ctilde
3×3 SparseArrays.SparseMatrixCSC{Float64,Int64} with 5 stored entries:
  [1, 1] = 3.0
  [2, 1] = 2.0
  [3, 1] = 1.0
  [2, 2] = 1.0
  [3, 3] = 1.0

```

Why? How can I directly get an ordinary matrix? (by “directly”, I mean without getting this sparse matrix and then converting it).

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [May 15, 2021, 11:42am UTC](https://discourse.julialang.org/t/why-do-i-get-a-sparse-matrix/61196/2 "2021-05-15T11:42:48Z")

</div>

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