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)
println(A)

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?

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)?

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.