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

**URL:** https://discourse.julialang.org/t/how-to-add-gaussian-noise-with-different-standard-deviations-to-different-elements-of-an-array/93906
**Category:** General Usage
**Tags:** question, package, signal-processing
**Created:** [February 2, 2023, 5:24am UTC](https://discourse.julialang.org/t/how-to-add-gaussian-noise-with-different-standard-deviations-to-different-elements-of-an-array/93906 "2023-02-02T05:24:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![CurioMath](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/curiomath/32/43603_2.png) [@CurioMath](https://discourse.julialang.org/u/CurioMath)
#### Post date: [February 2, 2023, 5:24am UTC](https://discourse.julialang.org/t/how-to-add-gaussian-noise-with-different-standard-deviations-to-different-elements-of-an-array/93906/1 "2023-02-02T05:24:25Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [February 2, 2023, 6:18am UTC](https://discourse.julialang.org/t/how-to-add-gaussian-noise-with-different-standard-deviations-to-different-elements-of-an-array/93906/2 "2023-02-02T06:18:04Z")

</div>

Something like this?

```julia
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

```
