Hello guys, I am wondering which should be the right strategy to fill values in a big sparse matrix.

I have a variable L, which is an n x m matrix, and is sparse. An outer loop runs on the row index, and just a few values of the row are non zero. The non zero values are contained in a vector d, which changes size in every iterations. The pseudo code would be something like this:

```
L=zeros(n,m)
for i in 1:m
for j in 1:n
L[i,j]=d[j]
end
end
```

Only 5% of the values are different from zero. If I initialize the matrix L as a Sparse Array (using spzeros), the code becomes slow (I found in another post that the best way to operate with sparse arrays is by just using the Is, Js, ans Vs vectors and build the matrix using the function sparse).

If a try to build a vector, only with the values of d (to then build the matrix L using the function sparse), since the size of d is unknown in each iteration, I have to initialize d as an empty vector that changes size in each loop, making it run slow once again.

For this particular case I can’t find a way to take advantage of the sparse arrays to make the code more efficient.

Any thoughts? Thanks