题目:
1:
`import numpy
import matplotlib.pyplot
X = numpy.arange(0, 2.00, 0.02)
Y = numpy.sin((X - 2) * numpy.exp(-X * 2)) * 2
matplotlib.pyplot.plot(X, Y)
matplotlib.pyplot.title(“A function”)
matplotlib.pyplot.xlabel(“X”)
matplotlib.pyplot.ylabel(“Y”)
matplotlib.pyplot.axis([0, 2, 0, 1])
matplotlib.pyplot.show()`
结果:
2:
from scipy import linalg
import numpy as np
import matplotlib.pyplot as plt
X = np.random.randint(0, 10, 200).reshape(20, 10)
b = np.random.randint(5, 15, 10).reshape(10, 1)
z = np.random.normal(size = 20).reshape(20, 1)
Y = np.dot(X, b) + z
b1 = np.linalg.lstsq(X, Y, rcond=None)[0]
plt.scatter(range(10), list(b.T), s=100)
plt.scatter(range(10), list(b1.T), s=100)
plt.legend(['True ','Estimated '])
plt.show()
结果如图
3:
from scipy import stats
import numpy
import matplotlib.pyplot
A = numpy.random.normal(loc = 1000, scale =100 , size = 10000)
n, bins, patches = matplotlib.pyplot.hist(A, bins = 25)
matplotlib.pyplot.plot(bins, stats.norm.pdf(bins, loc = 10000, scale = 100))
matplotlib.pyplot.show()
结果如图: