Hello,
I would like to initialize a sparse array A
of size N \times Nx, for which only the columns in dims
are non-zeros.
How can I improve this code?
using LinearAlgebra
using SparseArrays
N = 200
Nx = 20
dim = [1; 2; 5; 8; 10; 14; 17; 20]
A = sparse(repeat(1:N, length(dim)), vcat([i*ones(Int64, N) for i in dim]...), ones(N*length(dim)), N, Nx)