I am new to Julia and I have problems with the speed. What is the fastest way to replace rows in an array? Currently I iterate over any entry of a matrix and when the result of the associated calculation is nonzero, I store the position (row and col) and the value (aval) in an additional array that will serve for sparse matrix allocation at a later stage of the code.

The code here is a nonsense simplified example to get to the point. On my computer, the replacements in the if condition triple the computation time from around 0.04 seconds to 0.12 seconds. What am I doing wrong here?

Thanks in advance.

```
function testfun02(M)
nrow, ncol = size(M);
spidx = Array{Float64, 2}(undef, nrow, 3);
numit = 1;
for j02 = 1:ncol, j01 in 1:nrow
aval = M[j01,j02]*(j01+j02);
if aval > 0;
spidx[numit,1] = j01;
spidx[numit,2] = j02;
spidx[numit,3] = aval;
numit +=1;
end
end
return(spidx);
end
B = Matrix{Float64}(I, 10000, 10000);
@time testfun02(B);
```