[Numpy-discussion] Using normal()

Anne Archibald peridot.faceted@gmail....
Thu Apr 24 13:49:12 CDT 2008


On 24/04/2008, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Thu, Apr 24, 2008 at 10:01 AM, Rich Shepard <rshepard@appl-ecosys.com> wrote:
>  >    In the application's function I now have:
>  >
>  >    from numpy import *
>  >
>  >    x = nx.arange(0, 100, 0.1)
>  >    y = nx.normal(center,width)  # passed to the function when called
>  >
>  >  and I then pass x,y to PyX for plotting. But python responds with:
>  >
>  >    y = nx.normal(center,width)
>  >  AttributeError: 'module' object has no attribute 'normal'
>
> It's random.normal(loc, scale). But that will give you random x values
>  drawn from the normal distribution, not y values at your x. So you'll
>  have to code your own normal, which will probably look something like
>
>  norm = 1 / (scale * sqrt(2 * pi))
>  y = norm * exp(-power((x - loc), 2) / (2 * scale**2))

I really have to recommend you instead install scipy, which contains
this as well as many other probability distributions:

D = scipy.stats.norm(0, 1)

Then D.pdf(x) gives you the probability density function at x,
D.cdf(x) gives you the probability that the function value is less
than x, D.icdf(y) gives you the x value for which the probability is y
that the value will be less than x, and so on. This is also available
for more probability distributions than I had ever heard of.

Anne


More information about the Numpy-discussion mailing list