help?> sparse
...
sparse(I, J, V,[ m, n, combine])
Create a sparse matrix S of dimensions m x n such that S[I[k], J[k]] = V[k]. The combine function is used to combine duplicates. If m and n are not specified, they
are set to maximum(I) and maximum(J) respectively. If the combine function is not supplied, combine defaults to + unless the elements of V are Booleans in which case
combine defaults to |. All elements of I must satisfy 1 <= I[k] <= m, and all elements of J must satisfy 1 <= J[k] <= n. Numerical zeros in (I, J, V) are retained as
structural nonzeros; to drop numerical zeros, use dropzeros!.
For additional documentation and an expert driver, see Base.SparseArrays.sparse!.
Example
≡≡≡≡≡≡≡≡≡
julia> Is = [1; 2; 3];
julia> Js = [1; 2; 3];
julia> Vs = [1; 2; 3];
julia> sparse(Is, Js, Vs)
3×3 SparseMatrixCSC{Int64,Int64} with 3 stored entries:
[1, 1] = 1
[2, 2] = 2
[3, 3] = 3
Note that inserting elements on a non stored zero in a sparse matrix is quite expensive. If possible it might be worth building the matrix from I, J, V and then convert it to a sparse matrix to do operations that does not change the sparsity pattern.
In some applications you can use other construction methods too, e.g. spdiagm for sparse matrices with a banded structure, or Kronecker products (kron) of smaller sparse matrices for sparse matrices arising from regular grids (such as in finite-difference schemes).