# How do I check if a specific element in a sparse matrix is defined? (where the matrix possibly have 0-valued entries)

**URL:** <https://discourse.julialang.org/t/how-do-i-check-if-a-specific-element-in-a-sparse-matrix-is-defined-where-the-matrix-possibly-have-0-valued-entries/100947>\
**Category:** New to Julia\
**Created:** [June 28, 2023, 8:30pm UTC](https://discourse.julialang.org/t/how-do-i-check-if-a-specific-element-in-a-sparse-matrix-is-defined-where-the-matrix-possibly-have-0-valued-entries/100947 "2023-06-28T20:30:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 28, 2023, 8:30pm UTC](https://discourse.julialang.org/t/how-do-i-check-if-a-specific-element-in-a-sparse-matrix-is-defined-where-the-matrix-possibly-have-0-valued-entries/100947/1 "2023-06-28T20:30:26Z")

</div>

I have a sparse 2x2 matrix:

```julia
using SparseArrays
sm = SparseMatrixCSC(2, 2, [1, 3, 4], [1, 2, 1], [1.0, 0.0, 1.0])

```

that looks like:

```julia
 1.0 1.0
 0.0 ⋅ 

```

is there a way to check whenever element `[2,2]` is filled or not? Normally, I could do

```julia
sm[2,2] == 0.0

```

but that returns `true` both for `[2,1]` and `[2,2]`.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [June 28, 2023, 8:37pm UTC](https://discourse.julialang.org/t/how-do-i-check-if-a-specific-element-in-a-sparse-matrix-is-defined-where-the-matrix-possibly-have-0-valued-entries/100947/2 "2023-06-28T20:37:08Z")

</div>

```julia
julia> Base.isstored(sm,2,2)
false

julia> Base.isstored(sm,2,1)
true

```

maybe doing:

```julia
julia> import Base.isstored

julia> isstored(sm,2,2)
false

```

is nice if used a lot.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 28, 2023, 8:41pm UTC](https://discourse.julialang.org/t/how-do-i-check-if-a-specific-element-in-a-sparse-matrix-is-defined-where-the-matrix-possibly-have-0-valued-entries/100947/3 "2023-06-28T20:41:21Z")

</div>

Thanks!
