In [31]:
import numpy as np
import matplotlib.pyplot as plt
In [32]:
N=100000
x=np.random.normal(0,1,N)
y=1/x
In [33]:
plt.hist(x,bins=100,density=True)
xplot=np.arange(-5,5,0.01)
plt.plot(xplot,1/np.sqrt(2*np.pi)*np.exp(-xplot**2/2),c='red')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.show()
In [34]:
plt.hist(y,bins=100,range=(-10,10),density=True)
yplot=np.arange(-10,10,0.01)
plt.plot(yplot,1/np.sqrt(2*np.pi)*1/yplot**2*np.exp(-1/(2*yplot**2)),c='red')
plt.xlabel('y')
plt.ylabel('g(y)')
plt.show()
In [ ]: