python从数组

时间:2017-11-12 18:20:04

标签: python cdf

我有一个数组,让我们说该数组的100个成员。 我知道如何绘制cdf函数,但我的问题是,我想要数组的每个成员的cdf值。 我如何遍历数组并返回该数组成员的相应cdf值?

cumsum() and hist()

可以解决我的问题。我没有找到任何可以用来给我回复价值的图书馆。

norm.cdf() 

对我不起作用(出于任何原因)

例如

import matplotlib.pyplot as plt
import numpy as np
# create some randomly ddistributed data:
data = np.random.randn(10000)
# sort the data:
data_sorted = np.sort(data)
# calculate the proportional values of samples
p = 1. * arange(len(data)) / (len(data) - 1)
# plot the sorted data:
fig = figure()
ax1 = fig.add_subplot(121)
ax1.plot(p, data_sorted)
ax1.set_xlabel('$p$')
ax1.set_ylabel('$x$')

ax2 = fig.add_subplot(122)
ax2.plot(data_sorted, p)
ax2.set_xlabel('$x$')
ax2.set_ylabel('$p$')

绘制一条代表cdf的行(或两行)。我怎样才能从中获得价值?我的意思是图表后面有值,我怎样才能使用x的相应值?

但在我看来,它不完全正确。他只是将行数除以行数。并且它没有注意重复值:/

提前致谢

修改的 你会怎么说:

cur.execute("Select AGE From ****  ")
output = []
for row in cur:
  output.append(float(row[0]))
data_sorted = np.sort(output)
length=len(data_sorted)
yvals = np.arange(len(data_sorted))/float(len(data_sorted))
print yvals
plt.plot(data_sorted, yvals)
plt.show()

结果是,该数组长度为5个成员。这样每个成员都有一个1/5 = 0,2

这导致:

[ 1  2  2  9 58]
[ 0.   0.2  0.4  0.6  0.8]

但应该是1是0.2; 2是0,6(因为2出现2次,所以5中有3次是2次或更少)

如何获得0,6 ???

我的意思是,我可以在一个视图中写出来并总结一下,经过AGE分组但是,我不知道,宁愿在python中这样做...

0 个答案:

没有答案