Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Numpy Beginner's Guide (Update)
  • Toc
  • feedback
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

By : Ivan Idris
2 (1)
close
Numpy Beginner's Guide (Update)

Numpy Beginner's Guide (Update)

2 (1)
By: Ivan Idris

Overview of this book

This book is for the scientists, engineers, programmers, or analysts looking for a high-quality, open source mathematical library. Knowledge of Python is assumed. Also, some affinity, or at least interest, in mathematics and statistics is required. However, I have provided brief explanations and pointers to learning resources.
Table of Contents (16 chapters)
close
14
C. NumPy Functions' References
15
Index

Time for action – drawing the lognormal distribution

Let's visualize the lognormal distribution and its PDF with a histogram:

  1. Generate random numbers using the normal() function from the random NumPy module:
    N=10000
    lognormal_values = np.random.lognormal(size=N)
  2. Draw the histogram and theoretical PDF with a center value of 0 and standard deviation of 1:
    _, bins, _ = plt.hist(lognormal_values, np.sqrt(N), normed=True, lw=1)
    sigma = 1
    mu = 0
    x = np.linspace(min(bins), max(bins), len(bins))
    pdf = np.exp(-(numpy.log(x) - mu)**2 / (2 * sigma**2))/ (x * sigma * np.sqrt(2 * np.pi))
    plt.plot(x, pdf,lw=3)
    plt.show()

    The fit of the histogram and theoretical PDF is excellent, as you can see in the following diagram:

    Time for action – drawing the lognormal distribution

What just happened?

We visualized the lognormal distribution using the lognormal() function from the random NumPy module. We did this by drawing the curve of the theoretical PDF and a histogram of randomly generated values (see lognormaldist.py):

import numpy as np
import matplotlib...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete