【发布时间】:2020-06-17 23:03:44
【问题描述】:
这个功能我已经用过了:
np.random.seed(40)
np.random.normal(loc = 0, scale = 1, size = 10)
但是,我假设值应该在 1 和 -1 之间,对吧? 但我得到的值大于 1 且小于 -1。这怎么可能?
我得到了这个数组:
array([-0.6075477 , -0.12613641, -0.68460636, 0.92871475, -1.84440103,
-0.46700242, 2.29249034, 0.48881005, 0.71026699, 1.05553444])
您可以看到像 2.2924 和 -1.8 这样的值,这是标准偏差之外的范围
可能的解决方案
我已经制作了这段代码,可以吗?
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;
其中upper 和lower 是mean + std 和mean - std。 我首先生成了一个随机分布的数字,然后将其放入等式中。如果数字在特定范围之间,那么我将其添加到列表中
【问题讨论】:
-
正态分布不限于
[-1, 1]en.wikipedia.org/wiki/Normal_distribution
标签: python numpy statistics normal-distribution standard-deviation