擅长:python、mysql、java
<p>如前所述,来自<code>numpy</code>的<code>cumsum</code>工作良好。确保您的数据是正确的PDF(即总和为1),否则CDF不会以unity<a href="http://en.wikipedia.org/wiki/Cumulative_distribution_function" rel="noreferrer">as it should</a>结尾。下面是一个最小的工作示例:</p>
<pre><code>import numpy as np
from pylab import *
# Create some test data
dx = 0.01
X = np.arange(-2, 2, dx)
Y = exp(-X ** 2)
# Normalize the data to a proper PDF
Y /= (dx * Y).sum()
# Compute the CDF
CY = np.cumsum(Y * dx)
# Plot both
plot(X, Y)
plot(X, CY, 'r--')
show()
</code></pre>
<p><img src="https://i.stack.imgur.com/ci2ym.png" alt="enter image description here"/></p>