-
-
Save asw456/200cb9ebd5306deb63cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot | |
mu, sigma = 3., 1. # mean and standard deviation | |
s = np.random.lognormal(mu, sigma, 10000) | |
log_s = np.log(s) | |
subplot(211) | |
count,bins,_ = hist(s, 100, normed=True, align='mid') | |
x = np.linspace(min(bins), max(bins), 10000) | |
pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) / (x * sigma * np.sqrt(2 * np.pi))) | |
plot(x, pdf, linewidth=2, color='r') | |
axis('tight') | |
ylabel('relative frequency') | |
title('Log-normal distribution & log-normal samples histogram') | |
subplot(212) | |
count_log,bins_log,_ = hist(log_s, 100, normed=True, align='mid') | |
x_log = np.linspace(min(bins_log), max(bins_log), 10000) | |
pdf_log = (np.exp(-(x_log - mu)**2 / (2 * sigma**2)) / (sigma * np.sqrt(2 * np.pi))) | |
plot(x_log, pdf_log, linewidth=2, color='r') | |
axis('tight') | |
ylabel('relative frequency') | |
title('Normal distribution & log of log-normal samples histogram') | |
show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment