【发布时间】:2013-07-19 18:54:59
【问题描述】:
我的代码在给定范围 [0,1) 的情况下生成从 -10 到 10 的某个值 该代码将取值从 -10 到 10,并根据其概率将其附加到列表中。例如,-10 将被放入列表 0 次,因为它对应于值 0,而 10 将被放入 100 次(作为标准化),因为它对应于范围中的 1。
代码如下:
#!/usr/bin/env python
import math
import numpy as np
import matplotlib.pyplot as plt
pos = []
ceilingValue = 0.82
pValues = np.linspace(0.00, ceilingValue, num=100*ceilingValue)
for i in xrange(int(100*ceilingValue)):
p = pValues[i]
y = -11.63*math.log(-2.36279*(p - 1))
for j in xrange(i):
pos.append(y)
avg = np.average(pos)
std = np.std(pos)
hist, bins = np.histogram(pos,bins = 100)
width = 0.7*(bins[1]-bins[0])
center = (bins[:-1]+bins[1:])/2
plt.bar(center, hist, align = 'center', width = width)
plt.show()
问题在于直方图会生成准确的图,但某些值会破坏趋势。例如,-5.88 对应于频率计数中的大约 30 个条目,大约为 70。我认为 python 会看到这两个值并将它们简单地放在一起,但我不确定如何修复它。但如果只是直方图做错了,那没关系,我真的不需要它。我只需要列表,如果它首先是正确的。
【问题讨论】:
标签: python numpy histogram probability