简体   繁体   中英

How to generate N random numbers in Python for lognormal and exponential distribution?

The value of mean is 14 and std deviation is 1.4.When I tried with the formula random.lognormvariate(Mean,Sigma), I get very large values.It doesnt look like to be correct. Is ther eany other way to generate N random numbers for Lognormal distribution.

You can use numpy library for this purpose. It has a function for this purpose

import numpy as np
...
np.random.lognormal(Mean, Sigma)

Read more about it here

What you are doing is actually correct.

When you take the natural log of the normlog distributed value, you get the normal distributed value back:

import random as rd
from math import log
mean = 14
sigma = 1.4
rd_variable = rd.lognormvariate(mean, sigma)
print(log(rd_variable))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM