Is spzeros deprecated for creating sparse matrix in Julialang?

I am trying to understand how to create a sparse matrix in Julialang. The example project that I am learning in GitHub, I spotted spzeros() function which I believe it is going to create a sparse matrix. When I test following lines in Julialang terminal, it gave me error.

A = spzeros(20,0)

but I got this error:

ERROR: UndefVarError: spzeros not defined

I looked into the documentation and curious how spzeros() supposed to work in Julialang. Can anyone suggest me how should I create sparse matrix? Any idea? Thanks

Update: I tried SparseArrays(10,0) but still not working. Why? any idea?

you probably just need using SparseArrays

1 Like

it is not working. I got following error:

ERROR: UndefVarError: spzeros not defined

same error when I tried SparseArray(10,0). any other thoughts?

what version of Julia are you on? I just tested this and it really should work for anything 1.0 or newer.

1 Like

I think I used latest one: v.1.5.3

He meant

julia> using SparseArrays

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

Am confused why you would want a sparse array with size (20, 0)? (It cannot contain any element so I don’t think you can do anything with that, right?)

Maybe you wanted a sparse vector of length 20 instead? If that’s the case, use spzeros(20). Or if you want a sparse matrix that behaves like a column vector, maybe spzeros(20,1)?

1 Like

but it is valid to construct sparse matrix like spzeros(n,0) where n::Int, right? I am just playing around with Julia little bit. Maybe your possible extended discussion would be helpful. Thanks

Well, you can construct x = spzeros(10,0) yes, but you can’t fill it with any values AFAIK, because it has size(x,2) == 0, so I don’t know what you could potentially do with it.