# Example use of \`sparse!\`

**URL:** <https://discourse.julialang.org/t/example-use-of-sparse/21808>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 13, 2019, 7:49am UTC](https://discourse.julialang.org/t/example-use-of-sparse/21808 "2019-03-13T07:49:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [March 13, 2019, 8:05am UTC](https://discourse.julialang.org/t/example-use-of-sparse/21808/2 "2019-03-13T08:05:07Z")

</div>

If the sparsity patterns are guaranteed to always be static and identical, how about reusing the `colptr` and `rowval` vectors, as in this example:

```julia
julia> A = sprandn(10, 10, 0.05)
10×10 SparseMatrixCSC{Float64,Int64} with 5 stored entries:
  [3 , 1] = -0.00762068
  [4 , 3] = 0.24252
  [3 , 5] = -0.357867
  [3 , 9] = 0.451247
  [7 , 9] = 0.810302

julia> B = SparseMatrixCSC(size(A)..., SparseArrays.getcolptr(A), rowvals(A), rand(nnz(A)))
10×10 SparseMatrixCSC{Float64,Int64} with 5 stored entries:
  [3 , 1] = 0.506203
  [4 , 3] = 0.719589
  [3 , 5] = 0.336872
  [3 , 9] = 0.949761
  [7 , 9] = 0.59247

```

---

_[View the full topic](https://discourse.julialang.org/t/example-use-of-sparse/21808)._
