# Is spzeros(m,n) empty?

**URL:** <https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733>\
**Category:** General Usage\
**Created:** [July 24, 2019, 12:04pm UTC](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733 "2019-07-24T12:04:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsnyh](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bsnyh](https://discourse.julialang.org/u/bsnyh)\
**Post date:** [July 24, 2019, 12:04pm UTC](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733/1 "2019-07-24T12:04:27Z")

</div>

Based on my understanding, spzeros(m,n) would create a sparse matrix of zeros with size m\*n. I checked and found that calling isempty with a matrix like this would return false. What I do not understand is that, based on this link, [Sparse Arrays · The Julia Language](https://docs.julialang.org/en/v1/stdlib/SparseArrays/index.html),  
spzeros(m,n) is empty? …

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [July 24, 2019, 12:25pm UTC](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733/2 "2019-07-24T12:25:04Z")

</div>

`isempty` is meant to tell you if a collection has any elements in it ([docs](https://docs.julialang.org/en/v1/base/collections/index.html#Base.isempty)). A sparse matrix is an array, which Julia sees as a collection too, just like a vector `v = [0.0, 1.0]` is both a 1-dimensional array and a collection of two things (namely `0.0` and `1.0`). So `spzeros(m,n)` creates an n\times m sparse matrix which has n\*m elements – and so it’s not empty-- the elements just all happen to be zero.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [July 24, 2019, 12:26pm UTC](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733/3 "2019-07-24T12:26:24Z")

</div>

```julia
help?> isempty
search: isempty

  isempty(collection) -> Bool

  Determine whether a collection is empty (has no elements).

```

A spare matrix of all zeros has elements (all zeros) as long as its size is bigger than `(0,0)`. This is also consistent with how normal arrays behave.

---

<div class="post-metadata">

**Author:** ![shilu1984](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shilu1984/32/9512_2.png) [@shilu1984](https://discourse.julialang.org/u/shilu1984)\
**Post date:** [July 24, 2019, 4:31pm UTC](https://discourse.julialang.org/t/is-spzeros-m-n-empty/26733/4 "2019-07-24T16:31:29Z")

</div>

The function `nnz` may be what you want. For a sparse matrix A that does not store any nonzero element, there exists `nnz(A) == 0`
