Вы можете просто использовать индексированное назначение:
julia> using SparseArrays, LinearAlgebra
julia> S = spzeros(10,10)
10×10 SparseMatrixCSC{Float64,Int64} with 0 stored entries
julia> S[diagind(S)] = rand(10); S
10×10 SparseMatrixCSC{Float64,Int64} with 10 stored entries:
[1 , 1] = 0.2907
[2 , 2] = 0.451863
[3 , 3] = 0.920742
[4 , 4] = 0.0674684
[5 , 5] = 0.587077
[6 , 6] = 0.61916
[7 , 7] = 0.450401
[8 , 8] = 0.596222
[9 , 9] = 0.597324
[10, 10] = 0.210721