[Tutor] What is random.triangular() used for

Adam Bark 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
>> http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.triangular.html
>>
>>
>> """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."""
>>      
> Emile,
>
> 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,
>               normed=True)
> plt.show()
>
> 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?
>
> Dick
>    
I think he may be using ipython but putting an "import numpy as np" 
should get that code to work.
HTH
Adam.


More information about the Tutor mailing list