简体   繁体   English

如何生成具有特定标准差的随机正态分布

[英]How to generate a random normal distribution with specific standard deviation

I have already used this function :我已经使用过这个功能:

np.random.seed(40)
np.random.normal(loc = 0, scale = 1, size = 10)

However, I'm assuming the values should be between 1 and -1 right?但是,我假设这些值应该在 1 到 -1 之间,对吗? But I'm getting values that are larger than 1 and smaller than -1.但我得到的值大于 1 且小于 -1。 How is that possible?这怎么可能?

I'm getting this array :我得到这个数组:

array([-0.6075477 , -0.12613641, -0.68460636,  0.92871475, -1.84440103,
       -0.46700242,  2.29249034,  0.48881005,  0.71026699,  1.05553444])

You can see there're values like 2.2924 and also -1.8 which is ranges outside the standard deviation你可以看到有像 2.2924 和 -1.8 这样的值,这是标准偏差之外的范围

Possible solution可能的解决方案

I have made this code, is this okay?我已经制作了这个代码,可以吗?

final_data = []
count = 0
a = 26 # standard deviation
b = 157 # mean

for i in range(2000):
    y = a*np.random.normal(0, 1, 1) + b # equation to multiply by the std and add the mean
    if y <= upper and y >= lower :
        final_data.append(y[0])
        count += 1
        if count > 608:
            break;

Where upper and lower are the mean + std and mean - std.其中上限和下限是均值 + 标准差和均值 - 标准差。 I have first generated a randomly distributed number and then put it in the equation.我首先生成了一个随机分布的数字,然后将其放入等式中。 If the number is between the specific range, then I added it to the list如果数字在特定范围之间,那么我将其添加到列表中

Normal Distribution does not restrict the range of the values.正态分布不限制值的范围。 It just means that 68% of the values will be within 1 standard deviation of the mean;这只是意味着 68% 的值将在平均值的 1 个标准偏差内; 95% within 2 standard deviation and 99.7% within 3 standard deviations. 2 个标准偏差以内 95%,3 个标准偏差以内 99.7%。 Theoretically you could get any value from - infinty to infinity irrespective of your standard deviation.从理论上讲,无论您的标准偏差如何,您都可以获得从无穷大到无穷大的任何值。

Just to add to the previous comment and answer:只是为了添加到之前的评论并回答:

If you want to draw random numbers from an interval, you must choose a distribution with an upper and lower bound.如果要从区间中抽取随机数,则必须选择具有上限和下限的分布。 For example, the uniform distribution puts equal probability on every number between an upper and lower bound.例如,均匀分布对上下限之间的每个数字赋予相等的概率。 For numpy, you can check it out here: https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.random.uniform.html对于 numpy,您可以在此处查看: https : //docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.random.uniform.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 给定均值和标准差,生成二维正态分布 - Generate two-dimensional normal distribution given a mean and standard deviation 求出特定点距cdf的正态标准偏差和分布平均值 - Find normal standard deviation from the cdf at a specific point and the distribution mean 给定均值和标准差,如何计算正态分布的概率? - How to calculate probability in a normal distribution given mean & standard deviation? 生成一个 numpy random 查看从均值 1 和标准差 2 的正态分布中抽取的 100 个随机数的数组 - Generating a numpy random see array of 100 random numbers drawn from a normal distribution with mean 1 and standard deviation 2 给定均值和标准差,根据几何分布和二项分布生成随机数 - Given a mean and standard deviation generate random numbers based on a geometric distribution and binomial distribution 如何生成整数的随机正态分布 - How to generate a random normal distribution of integers 如何从标准正态值生成多元正态分布? - How to generate multivariate Normal distribution from a standard normal value? 标准C或Python库,用于计算正态分布的标准偏差 - Standard C or Python libraries to compute standard deviation of normal distribution 如何在Python中获取600个值的均值为零且标准偏差为σ= 2 dB的对数正态分布(即以dB为单位的正态分布)? - How to get log-normal distribution (i.e. a normal distribution in dB) with a zero mean and a standard deviation of σ = 2 dB for 600 values in python? 使用 jax.random.normal 对具有特定均值和标准差的单变量高斯分布进行采样 - sampling univariate gausssian with specific mean and standard deviation using jax.random.normal
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM