Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding scipy.stats.norm.rvs()?

Tags:

In scipy.stats.norm.rvs() the argument scale denotes standard deviation but in the below piece of code sigma_list refers to an array. How does the code actually work?

Where sigma_list is obtained by following code:

sigma=0.06

mask=(x > 0.65) & (x < 0.8)

sigma_list=sigma+mask*0.03

sigma_list

y = sp.stats.norm.rvs(scale=sigma_list, size=200)

Even the standard deviations of both sigma_list and y are also not matching

I want to know the working of the above scipy module

sorry, i didn't mention that x is an array of values between 0 and 1

like image 779
Manoj Kumar Avatar asked Jun 09 '17 08:06

Manoj Kumar


1 Answers

In your code, the mask will be either True or False here. So if you do some addition or subtraction, it is respectively translated into 1 or 0.

Then the result of sigma_list is not a list nor an array but a floating value. Looking at the documentation, you can see its usage.

rvs(loc=0, scale=1, size=1, random_state=None)

If you look at the code (line 2771) you have:

loc : array_like, optional Location parameter (default=0).

size : int or tuple of ints, optional Defining number of random variates (Default is 1). Note that size has to be given as keyword, not as positional argument.

random_state : None or int or np.random.RandomState instance, optional If int or RandomState, use it for drawing the random variates. If None, rely on self.random_state. Default is None.

like image 186
tupui Avatar answered Oct 11 '22 12:10

tupui