python求概率密度函数,如何在Python中计算PDF(概率密度函数)?

I have the following code below that prints the PDF graph for a particular mean and standard deviation.

Now I need to find the actual probability, of a particular value. So for example if my mean is 0, and my value is 0, my probability is 1. This is usually done by calculating the area under the curve. Similar to this:

I am not sure how to approach this problem

import numpy as np

import matplotlib

import matplotlib.pyplot as plt

def normal(power, mean, std, val):

a = 1/(np.sqrt(2*np.pi)*std)

diff = np.abs(np.power(val-mean, power))

b = np.exp(-(diff)/(2*std*std))

return a*b

pdf_array = []

array = np.arange(-2,2,0.1)

print array

for i in array:

print i

pdf = normal(2, 0, 0.1, i)

print pdf

pdf_array.append(pdf)

plt.plot(array, pdf_array)

plt.ylabel('some numbers')

plt.axis([-2, 2, 0, 5])

plt.show()

print

解决方案

Unless you have a reason to implement this yourself. All these functions are available in scipy.stats.norm

I think you asking for the cdf, then use this code:

from scipy.stats import norm

print(norm.cdf(x, mean, std))

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值