# Delete! in sparse matrix

**URL:** https://discourse.julialang.org/t/delete-in-sparse-matrix/2634
**Category:** General Usage
**Created:** [March 13, 2017, 8:53am UTC](https://discourse.julialang.org/t/delete-in-sparse-matrix/2634 "2017-03-13T08:53:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![CarloLucibello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carlolucibello/32/3278_2.png) [@CarloLucibello](https://discourse.julialang.org/u/CarloLucibello)
#### Post date: [March 13, 2017, 8:53am UTC](https://discourse.julialang.org/t/delete-in-sparse-matrix/2634/1 "2017-03-13T08:53:08Z")

</div>

suppose you have the following sparse matrix

```julia
julia> type A end

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

julia> m[1,1] = A()
A()

```

Now I would like to remove the element in (1,1).  
If `m` was a dictionary I would use `delete!(m, (1,1))`. Is there a similar method for sparse matrices?

Cheers,  
Carlo

---

<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: [March 13, 2017, 8:59am UTC](https://discourse.julialang.org/t/delete-in-sparse-matrix/2634/2 "2017-03-13T08:59:49Z")

</div>

You need to define what “zero” means for your type, consider:

```julia
julia> m[1,2]
------ MethodError --------------------- Stacktrace (most recent call last)

 [1] — getindex(::SparseMatrixCSC{A,Int64}, ::Int64, ::Int64) at sparsematrix.jl:2092

MethodError: no method matching zero(::Type{A})
Closest candidates are:
  zero(::Type{Base.LibGit2.Oid}) at libgit2/oid.jl:88
  zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuildItem}) at pkg/resolve/versionweight.jl:80
  zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuild}) at pkg/resolve/versionweight.jl:120
  ...

```

Once you’ve done that, set `m[1,1]=your_zero`. If you want to free the memory used now storing a “zero” at `m[1,1]` use `dropzero!`.

---

<div class="post-metadata">

### Author: ![CarloLucibello](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carlolucibello/32/3278_2.png) [@CarloLucibello](https://discourse.julialang.org/u/CarloLucibello)
#### Post date: [March 13, 2017, 9:52am UTC](https://discourse.julialang.org/t/delete-in-sparse-matrix/2634/3 "2017-03-13T09:52:31Z")

</div>

nice, thanks!
