# Column pointers of sparse array in case of empty columns

**URL:** <https://discourse.julialang.org/t/column-pointers-of-sparse-array-in-case-of-empty-columns/77924>\
**Category:** New to Julia\
**Tags:** sparse\
**Created:** [March 15, 2022, 6:18pm UTC](https://discourse.julialang.org/t/column-pointers-of-sparse-array-in-case-of-empty-columns/77924 "2022-03-15T18:18:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmeer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mmeer/32/33931_2.png) [@mmeer](https://discourse.julialang.org/u/mmeer)\
**Post date:** [March 15, 2022, 6:18pm UTC](https://discourse.julialang.org/t/column-pointers-of-sparse-array-in-case-of-empty-columns/77924/1 "2022-03-15T18:18:34Z")

</div>

Hi there,

I’ve noticed something that isn’t well-documented imho.

When a sparse matrix has an empty column `i`, what is `colptr[i]`?

Example:

```julia
sparse(Matrix(S))
3×3 SparseMatrixCSC{Float64, Int64} with 3 stored entries:
 0.360646 ⋅ ⋅ 
  ⋅ ⋅ 0.688464
 0.230095 ⋅ ⋅

```

gives

```julia
S.colptr
4-element Vector{Int64}:
 1
 3
 3
 4

```

The [Sparse Arrays documentation](https://docs.julialang.org/en/v1/stdlib/SparseArrays/) says

```julia
colptr::Vector{Ti} # Column j is in colptr[j]:(colptr[j+1]-1)

```

Can anyone elucidate?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 15, 2022, 6:28pm UTC](https://discourse.julialang.org/t/column-pointers-of-sparse-array-in-case-of-empty-columns/77924/2 "2022-03-15T18:28:46Z")

</div>

> [@mmeer](#):
>
> When a sparse matrix has an empty column `i` , what is `colptr[i]` ?

The number of elements in column `i` is `colptr[i+1]-colptr[i]`, so for an empty column you simply have `colptr[i+1] == colptr[i]`.
