Does the noise cause a random case in the array of values?

I saw this template from someone code:

import numpy as np # Create array xx = np.linspace(0.0, 100.0, num=100) # Add Noise xx = np.random.normal(xx) 

and it seems that for each value of the array some noise is added, but I can not find any documentation for this. What's happening? What determines the properties (e.g. scaling) of noise? Is this value considered as the average value (i.e., loc parameter) of each sample from the normal distribution?

I would also be very interested to know why this behavior is not covered in the documentation.

+6
source share
2 answers

I donโ€™t see this being documented, but many of the numpy functions that accept ndarray will work with it elementary . In any case, you can easily verify that when passing the array, it calls numpy.random.normal for each element of the array, using this element value as average and returns the array:

 In [9]: xx = numpy.array([1, 10, 100, 1000]) In [10]: numpy.random.normal(xx) Out[10]: array([ 9.45865328e-01, 1.11542264e+01, 9.88601302e+01, 1.00120448e+03]) 

It looks like it uses the default value of 1.0 for the scale. You can override this though:

 In [12]: numpy.random.normal(xx, 10) Out[12]: array([ 8.92500743, -5.66508088, 97.33440273, 1003.37940455]) In [13]: numpy.random.normal(xx, 100) Out[13]: array([ -75.13092966, -47.0841671 , 154.12913986, 816.3126146 ]) 
+8
source

As a complement to the comments and example above, the documentation is in my numpy implementation.
In abbreviated form with large legs:

 help(np.random.normal) normal(loc=0.0, scale=1.0, size=None) Draw random samples from a normal (Gaussian) distribution. Parameters ---------- loc : float Mean ("centre") of the distribution. scale : float Standard deviation (spread or "width") of the distribution. size : tuple of ints, Output shape. If the given shape is, eg, ``(m, n, k)``, then ``m * n * k`` samples are drawn. 

If you want to create a series of data values โ€‹โ€‹with a specific shape, oriented by the average value with a given standard deviation, you can do the following.

 >>> x = 10 >>> vals = np.random.normal(x,3.,(10,)) >>> vals array([ 10.6999745 , 9.58139692, 14.04490407, 9.54797132, 10.18378835, 11.42772729, 5.22100578, 9.51757533, 12.95314676, 13.77068901]) 

which generates an array of 10 values, form (10) with an average value of 10 and values โ€‹โ€‹scattered within ยฑ 3 standard deviations. The actual distribution function, links, and matplotlib sample code are also presented. I am using np.version.version '1.8.0'.

This is a useful feature if you want to create point patterns (X, Y) centered around the mean with a known spread.

+1
source

Source: https://habr.com/ru/post/989981/


All Articles