# Is spzeros deprecated for creating sparse matrix in Julialang?

**URL:** <https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 19, 2021, 4:50am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582 "2021-01-19T04:50:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_shay](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Jared\_shay](https://discourse.julialang.org/u/Jared_shay)\
**Post date:** [January 19, 2021, 4:50am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/1 "2021-01-19T04:50:56Z")

</div>

I am trying to understand how to create a sparse matrix in Julialang. The example project that I am learning in GitHub, I spotted `spzeros()` function which I believe it is going to create a sparse matrix. When I test following lines in Julialang terminal, it gave me error.

```julia
A = spzeros(20,0)
println(A)

```

but I got this error:

> ERROR: UndefVarError: spzeros not defined

I looked into the documentation and curious how `spzeros()` supposed to work in Julialang. Can anyone suggest me how should I create sparse matrix? Any idea? Thanks

**Update** : I tried `SparseArrays(10,0)` but still not working. Why? any idea?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 19, 2021, 5:24am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/2 "2021-01-19T05:24:52Z")

</div>

you probably just need `using SparseArrays`

---

<div class="post-metadata">

**Author:** ![Jared\_shay](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Jared\_shay](https://discourse.julialang.org/u/Jared_shay)\
**Post date:** [January 19, 2021, 5:30am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/3 "2021-01-19T05:30:01Z")

</div>

it is not working. I got following error:

> ERROR: UndefVarError: spzeros not defined

same error when I tried `SparseArray(10,0)`. any other thoughts?

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 19, 2021, 5:32am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/4 "2021-01-19T05:32:44Z")

</div>

what version of Julia are you on? I just tested this and it really should work for anything 1.0 or newer.

---

<div class="post-metadata">

**Author:** ![Jared\_shay](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Jared\_shay](https://discourse.julialang.org/u/Jared_shay)\
**Post date:** [January 19, 2021, 5:37am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/5 "2021-01-19T05:37:11Z")

</div>

I think I used latest one: v.1.5.3

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 19, 2021, 5:41am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/6 "2021-01-19T05:41:39Z")

</div>

> [@Jared\_shay](#):
>
> I tried `SparseArray(10,0)`

He meant

```julia
julia> using SparseArrays

julia> A = spzeros(20,0)
20×0 SparseMatrixCSC{Float64, Int64} with 0 stored entries

```

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [January 19, 2021, 6:06am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/7 "2021-01-19T06:06:22Z")

</div>

Am confused why you would want a sparse array with size `(20, 0)`? (It cannot contain any element so I don’t think you can do anything with that, right?)

Maybe you wanted a sparse vector of length `20` instead? If that’s the case, use `spzeros(20)`. Or if you want a sparse matrix that behaves like a column vector, maybe `spzeros(20,1)`?

---

<div class="post-metadata">

**Author:** ![Jared\_shay](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@Jared\_shay](https://discourse.julialang.org/u/Jared_shay)\
**Post date:** [January 19, 2021, 6:20am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/8 "2021-01-19T06:20:30Z")

</div>

but it is valid to construct sparse matrix like `spzeros(n,0)` where `n::Int`, right? I am just playing around with Julia little bit. Maybe your possible extended discussion would be helpful. Thanks

---

<div class="post-metadata">

**Author:** ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Post date:** [January 19, 2021, 6:25am UTC](https://discourse.julialang.org/t/is-spzeros-deprecated-for-creating-sparse-matrix-in-julialang/53582/9 "2021-01-19T06:25:51Z")

</div>

Well, you can construct `x = spzeros(10,0)` yes, but you can’t fill it with any values AFAIK, because it has `size(x,2) == 0`, so I don’t know what you could potentially do with it.
