[Tutor] What is random.triangular() used for
adam.jtm30 at gmail.com
Sun Oct 24 23:13:14 CEST 2010
On 24/10/10 21:57, Richard D. Moores wrote:
> On Sun, Oct 24, 2010 at 13:29, Emile van Sebille<emile at fenx.com> wrote:
>> From people who would know found at
>> """The triangular distribution is often used in ill-defined problems where
>> the underlying distribution is not known, but some knowledge of the limits
>> and mode exists. Often it is used in simulations."""
> from the source code link on that page, I got
> # Draw values from the distribution and plot the histogram:
> import matplotlib.pyplot as plt
> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200,
> Which when I run it I get
> Traceback (most recent call last):
> File "c:\P26Working\untitled-8.py", line 2, in<module>
> h = plt.hist(np.random.triangular(-3, 0, 8, 100000), bins=200, normed=True)
> NameError: name 'np' is not defined
> Process terminated with an exit code of 1
> The import goes OK:
>>>> import matplotlib.pyplot as plt
> and apparently I have numpy, if that's relevant:
>>>> import numpy
> but where do I get np?
I think he may be using ipython but putting an "import numpy as np"
should get that code to work.
More information about the Tutor