简体   繁体   English

使用 numpy.random.randn() 生成的正态分布均值不是“0”

[英]Mean of normal distribution generated using numpy.random.randn() is not '0'

I am trying to follow this tutorial from quantopian where they are trying to show that samples progressively exhibit characteristics of a normal distribution with increase in size.我正在尝试从 quantopian 遵循本教程,他们试图证明样本随着大小的增加逐渐表现出正态分布的特征。

I tried to generate a normal distribution using the numpy.random.randn() method as shown in the tutorial.我尝试使用numpy.random.randn()方法生成正态分布,如教程中所示。

I understand that this method returns a sample of the standard normal distribution and that for a normal distribution, mean = 0 and standard deviation = 1我了解此方法返回标准正态分布的样本,对于正态分布, mean = 0standard deviation = 1

But , when I check the mean and standard deviation of this distribution, they show weird values ie mean = 0.23 and standard deviation = 0.49 .但是,当我检查该分布的均值和标准差时,它们显示出奇怪的值,即mean = 0.23standard deviation = 0.49

CODE:代码:

import numpy as np
import matplotlib.pyplot as plt
#np.random.seed(123)
normal = np.random.randn(6)

print (normal.mean())
print (normal.std())

RESULT:结果:

0.231567632423
0.488577812058

I am guessing this could be because I am looking at just a sample and not the whole distribution and it is not perfectly normal.我猜这可能是因为我只看一个样本而不是整个分布,这并不完全正常。 But if that is the case:但如果是这样的话:

  1. What characteristics should I expect from this sample?我应该从这个样本中得到什么特征?

  2. Isn't the tutorial's suggestion wrong, since it will never be a normal distribution?教程的建议是不是错误的,因为它永远不会是正态分布?

You have a sample size or 6. It is not sufficiently large enough to get close to approximating the normal distribution.您的样本大小为 6。它不够大,无法接近正态分布。 Try it with 600 or 6000 to get a good representation of the distribution.尝试使用 600 或 6000 以获得分布的良好表示。

import numpy as np

x = np.random.randn(600)
x.mean(), x.std()
# returns:
(-0.07760043571247623, 0.9664411074909558)

x = np.random.randn(6000)
x.mean(), x.std()
# returns:
(0.003908119246211815, 1.0001989021750033)

The average roll of a 6-sided die should be 3.5. 6 面骰子的平均掷骰数应为 3.5。 However, if you only roll it 6 times, it is unlikely you will have an average of 3.5.但是,如果您只滚动 6 次,您的平均数不太可能达到 3.5。

暂无
暂无

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

相关问题 具有类属性__iadd__(+ =)和numpy.random.randn()的奇怪行为 - Weird behavior with class attribute, __iadd__ (+=) and numpy.random.randn() 如何将一维维度数组输入到 numpy.random.randn 中? - How to input a 1-D array of dimensions into numpy.random.randn? 使用 numpy.random.randn() 在 numpy 中初始化随机权重矩阵时出现“TypeError: an integer is required” - 'TypeError: an integer is required' when initializing random weight matrix in numpy with numpy.random.randn() 什么时候使用numpy.random.randn(…)?什么时候使用numpy.random.rand(…)? - When to use numpy.random.randn(…) and when numpy.random.rand(…)? Python 中 numpy.random.rand 与 numpy.random.randn 之间的差异 - Differences between numpy.random.rand vs numpy.random.randn in Python 使用 numpy 获取从标准正态分布生成的随机样本的方差值 - Getting variance values for random samples generated from a standard normal distribution using numpy 使用 Numpy 的正态分布 - Normal Distribution using Numpy 生成一个 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 为什么numpy随机法线会生成错误的均值错误的随机矩阵? - Why numpy random normal generated a wrong random matrix with wrong mean value? numpy.random.normal不同分布:从分布中选择值 - numpy.random.normal different distribution: selecting values from distribution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM