高编作业(九)
程序员文章站
2022-07-12 23:39:51
...
Matplotlib作业
1
题目截图
代码
from scipy import linalg
import numpy as np
import matplotlib.pyplot as plt
X = np.arange(0, 2.02, 0.02)
Y = np.sin((X - 2) * np.exp(-X ** 2)) ** 2
plt.plot(X, Y)
plt.title("New Plot")
plt.xlabel("X")
plt.ylabel("Y")
plt.axis([0, 2, -0.02, 1.02])
plt.show()
结果截图
2
题目截图
代码
from scipy import linalg
import numpy as np
import matplotlib.pyplot as plt
# 生成X、Y、b
X = np.random.randint(-7, 7, 220).reshape(20, 11)
X[:, 0] = 1
b = np.random.randint(-5, 5, 11).reshape(11, 1)
while 0 in b:
b = np.random.randint(-5, 5, 11).reshape(11, 1)
z = np.random.normal(size = 20).reshape(20, 1)
Y = np.dot(X, b) + z
# 最小二乘法生成系数
assume_b = np.dot(np.dot(np.linalg.inv(np.dot(X.T, X)), X.T), Y)
plt.plot(b, 'ro', assume_b, 'bx')
plt.legend(['True', 'Estimate'])
plt.show()
结果截图
3
题目截图
代码
from scipy import stats
import numpy as np
import matplotlib.pyplot as plt
A = np.random.normal(loc = 100, scale = 5, size = 10000)
n, bins, patches = plt.hist(A, bins = 25, edgecolor='black', density=1)
plt.plot(bins, stats.norm.pdf(bins, loc = 100, scale = 5))
plt.show()
结果截图
上一篇: win10 添加右键 cmd(管理员)
下一篇: 【考研每日一题37】取中值(C++)