# Bug with initializing extra rows in sparse arrays

**URL:** <https://discourse.julialang.org/t/bug-with-initializing-extra-rows-in-sparse-arrays/83594>\
**Category:** General Usage\
**Tags:** bug, sparse\
**Created:** [July 1, 2022, 2:30am UTC](https://discourse.julialang.org/t/bug-with-initializing-extra-rows-in-sparse-arrays/83594 "2022-07-01T02:30:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsbryan4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsbryan4/32/34173_2.png) [@jsbryan4](https://discourse.julialang.org/u/jsbryan4)\
**Post date:** [July 1, 2022, 2:30am UTC](https://discourse.julialang.org/t/bug-with-initializing-extra-rows-in-sparse-arrays/83594/1 "2022-07-01T02:30:09Z")

</div>

I found what I believe to be a bug in SparseArrays. If I try to make a sparse array with more rows than the max row number It fails with the error:

```julia
11×10 SparseMatrixCSC{Any, Int64} with 100 stored entries:
ERROR: MethodError: no method matching zero(::Type{Any})

```

Note that it actually creates the array A and I can do math with it, but for some reason it cannot display A. A minimum example of faliure is the following:

```julia
using SparseArrays

N = 10
M = 1

rows = []
cols = []
vals = []
for i = 1:N
    for j = 1:N
    push!(rows, i)
    push!(cols, j)
    push!(vals, 1)
    end
end

A = sparse(rows, cols, vals, N+M, N)

```

to make is stranger, if you set M to be 1,2,3,4, or 5 it fails, but if you set M\>5 it works.

---

<div class="post-metadata">

**Author:** ![jsbryan4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jsbryan4/32/34173_2.png) [@jsbryan4](https://discourse.julialang.org/u/jsbryan4)\
**Post date:** [July 1, 2022, 2:36am UTC](https://discourse.julialang.org/t/bug-with-initializing-extra-rows-in-sparse-arrays/83594/2 "2022-07-01T02:36:59Z")

</div>

I discovered that the issue is resolved if I specify the type of the vectors that make up A like

```julia
rows = Int[]
cols = Int[]
vals = Float64[]

```

It is still strange to me why I don’t have to do this when M\>5.
