Hi all,
The first thing I would like to do is use the library matplotlib
to plot the normal distrubution with μ = 0
and σ = 1
.
To import matplotlib you use the statement:
import matplotlib.pyplot as plt
Now you can plot make plots using plt.plot()
like plt.plot([0,1,2,3],[0,1,2,3])
, and to show them use plt.show()
(it might be different on juipiter).
To make this plot, I would like you to use numpy.linspace
; to import:
from numpy import linspace
You can use linspace like so:
linspace(0,1,11)
#OUTPUTS: array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])
An incredibly useful skill with programming is being able to formulate your questions and querying them on Google, or DuckDuckGo to find your answer. I would like you to do that to learn about linspace and matplotlib.pyplot; also, feel free to ask me questions on discord.
The task is follows:
- Plot a normal distribution with
μ = 0
andσ = 1
- Find the maximum y-value of this plot. The constant in front of the exponential component of the equation can be 1 or 1/sqrt(2*pi*sigma^2) or you can find the max y-value for both.
Some of you have already done this so here is another plot I would like to see:
- Plot the random distribution using
from random import random
;random()
will output a real number between 0-1. Generate an array of10,000
random numbers, and plot them using the matplot lib histogram. If my array of random numbers was[.4,.2,.053]
, I would plot them likeplt.hist([.4,.2,.053])
. - Find the standard devation and average of the random distribution. If you are using python3 you can import the statistics library using
import statistics
, then to find the standard devation and mean is simply:statistics.stdev([.4,.2,.053])
andstatistics.mean([.4,.2,.053])
. Again, I am assuming my list of random numbers is[.4,.2,.053]
.