简体   繁体   English

当在 python 中为正态分布绘制 pdf 并且标准偏差为 2 时,平均值是否仍然为零?

[英]when plotting a pdf in python for a normal distribution and the standard deviation is 2, will the mean still be zero?

So based on my understanding of normal distribution the mean is zero by default when the standard deviation is 1. I was given an assignment to write a python program to generate a PDF of a normally distributed function with the range from 10 to 45 with a standard deviation of 2. Will the mean still be zero?因此,根据我对正态分布的理解,当标准差为 1 时,默认情况下均值为零。 2 的偏差。均值仍然为零吗? I tried this but my plot doesn't form a bell shape.我试过了,但我的情节没有形成钟形。 I don't know what I am doing wrong.我不知道我做错了什么。

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
mu=0 # mean
sigma=2
x=np.arange(10,45,0.1)
y=stats.norm.pdf(x, 0, sigma)
plt.plot(x,y)
plt.show()

See my plot here: myplot在这里查看我的情节: myplot

Here since the range of random variables is between 10 to 45, so the mean will lie in between this range of values, around 27. You need to get the same using the mean function and then use your code as follows:这里因为随机变量的范围在 10 到 45 之间,所以平均值将位于这个值范围之间,大约为 27。您需要使用 mean 函数获得相同的值,然后使用您的代码如下:

y=stats.norm.pdf(x, x.mean(), sigma )

This will give you a normal distribution curve这会给你一个正态分布曲线代码快照

from scipy.stats import norm
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10,45,0.1)
sigma = 2
print('Mean :', round(x.mean(), 2),'SD :', sigma)
plt.plot(x, norm.pdf(x,x.mean(),sigma), 'r1', lw=2, alpha=0.5, label='norm PDF')
plt.legend(loc='best')
plt.show()

Which prints:哪个打印:

Mean : 27.45 SD : 2

And shows the shape of the probability density function:并显示了概率密度函数的形状:

在此处输入图片说明

暂无
暂无

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

相关问题 如何在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? 直方图、均值、标准差的正态分布,在数组的某个部分内 - Normal distribution of histogram, mean, standard deviation, within a certain part of an array 求出特定点距cdf的正态标准偏差和分布平均值 - Find normal standard deviation from the cdf at a specific point and the distribution mean 给定均值和标准差,生成二维正态分布 - Generate two-dimensional normal distribution given a mean and standard deviation 给定均值和标准差,如何计算正态分布的概率? - How to calculate probability in a normal distribution given mean & standard deviation? 标准C或Python库,用于计算正态分布的标准偏差 - Standard C or Python libraries to compute standard deviation of normal distribution 标准偏差Python绘图 - Standard Deviation Python Plotting 如何从 Python 中的频率分布表中获取均值和标准差 - How to get Mean and Standard deviation from a Frequency Distribution table in Python SciPy 统计对数正态分布 获得 pdf 给定对数正态分布均值和对数正态分布几何标准差 - SciPy stats lognormal distribution obtain pdf with given lognormal distribution mean and lognormal distribution geometric standard deviation 在 Python (Seaborn) 中绘制包括标准差在内的多列的平均值 - Plotting the mean of multiple columns including standard deviation in Python (Seaborn)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM