# Writing a simple Gaussian noise layer in Pytorch

**URL:** <https://discuss.pytorch.org/t/writing-a-simple-gaussian-noise-layer-in-pytorch/4694>\
**Category:** Uncategorized\
**Created:** [July 7, 2017, 10:57am UTC](https://discuss.pytorch.org/t/writing-a-simple-gaussian-noise-layer-in-pytorch/4694 "2017-07-07T10:57:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fmassa](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/fmassa/32/58_2.png) [@fmassa](https://discuss.pytorch.org/u/fmassa)\
**Post date:** [July 9, 2017, 10:55am UTC](https://discuss.pytorch.org/t/writing-a-simple-gaussian-noise-layer-in-pytorch/4694/2 "2017-07-09T10:55:17Z")

</div>

Yes, you can move the mean by adding the mean to the output of the normal variable.  
But, a maybe better way of doing it is to use the `normal_` function as follows:

```auto
def gaussian(ins, is_training, mean, stddev):
    if is_training:
        noise = Variable(ins.data.new(ins.size()).normal_(mean, stddev))
        return ins + noise
    return ins

```

---

_[View the full topic](https://discuss.pytorch.org/t/writing-a-simple-gaussian-noise-layer-in-pytorch/4694)._
