# How to add gaussian noise with different standard deviations to different elements of an array?

Hi,
I have an array of measurements of different variables, of varying magnitude, to which I have to add gaussian noise. But note that I have to add noise with different standard deviation to each measurement(i.e. to each array element), as different variables have different noise levels.

I have checked Noise.jl, but there it adds noise to entire array elements with the same standard deviation…

Is there some way out there to do this? Or can I know if there is some option to add gaussian noise to a single variable rather than to an array?
Any possible help is appreciated!

Something like this?

``````julia> X = hcat((fill(Float64(i),5) for i in [1,10,100])...)
5×3 Matrix{Float64}:
1.0  10.0  100.0
1.0  10.0  100.0
1.0  10.0  100.0
1.0  10.0  100.0
1.0  10.0  100.0

julia> noise_level = [10.0^(i-2) for i in axes(X,2)]
3-element Vector{Float64}:
0.1
1.0
10.0

julia> X .+= randn(size(X)) .* noise_level'
5×3 Matrix{Float64}:
1.10089   11.0003    94.9374
0.955057   9.54158   93.1862
1.04305   10.7635    99.0186
1.04834    9.77558   96.5131
0.965511   8.75656  107.612
``````
2 Likes