第十二周作业
程序员文章站
2022-06-20 10:42:03
...
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
x = np.linspace(0,2,100)
y = np.power(np.sin(x-2),2)*np.exp((-1)*np.power(x,2))
fig = plt.figure()
axes = fig.add_axes([0.1,0.1,0.8,0.8])
axes.plot(x,y)
axes.set_xlabel('x')
axes.set_ylabel('y')
axes.set_xlim((0,2))
axes.set_ylim((0,1))
axes.set_title('Exercise 11.1')
plt.show()
>>> import numpy as np
>>> import matplotlib as mpl
>>> import matplotlib.pyplot as plt
>>> X = np.random.rand(20,10)
>>> b = np.random.rand(10,1)
>>> z = np.random.rand(20,1)
>>> y = np.dot(X,b)+z
>>> D = np.dot(np.transpose(X),X)
>>> d = np.dot(np.transpose(X),y)
>>> _b = np.dot(np.linalg.inv(D),d)
>>> a = np.linspace(0,9,10)
>>> fig,axes = plt.subplots()
>>> ax.grid(linestyle='-')
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
ax.grid(linestyle='-')
NameError: name 'ax' is not defined
>>> axes.grid(linestyle='-')
>>> True_Cofficient = axes.plot(a,b,'bo')
>>> Estimate_Cofficient = axes.plot(a._b,'r+')
Traceback (most recent call last):
File "<pyshell#41>", line 1, in <module>
Estimate_Cofficient = axes.plot(a._b,'r+')
AttributeError: 'numpy.ndarray' object has no attribute '_b'
>>> Estimate_Cofficient = axes.plot(a,_b,'r+')
>>> plt.legend([True_Cofficient,Estimate_Cofficient],['True cofficients','Estimated cofficients'])
>>> axes.set_xlabel('Index')
Text(0.5,0,'Index')
>>> axes.set_ylabel('Value')
Text(0,0.5,'Value')
>>> axes.set_xlim((0,10))
(0, 10)
>>> axes.set_ylim((-2,2))
(-2, 2)
>>> axes.set_title('Exercise 11.2')
Text(0.5,1,'Exercise 11.2')
>>> plt.show()
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import matplotlib
z=np.random.randn(10000)
figure,axes=plt.subplots()
c,d,e=axes.hist(z, bins=25,color='b',density=True)
axes.set_title('Exercise 11.3:')
plt.setp(e, edgecolor='k')
kernel=stats.gaussian_kde(z)
x=np.linspace(-4,4,1000)
y=kernel.pdf(x)
axes.plot(x,y,'k-')
plt.show()
上一篇: 第十二周作业
下一篇: 数据库设计规范,需要注意几点!
推荐阅读
-
SQL Server 作业的备份(备份作业非备份数据库)
-
Win10周年更新累积更新KB3201845补丁更新内容大全
-
Win10周年更新(版本1607)累积更新KB3201845解决修复内容汇总
-
Win10 Mobile一周年更新14393.594预览版推送
-
Win10周年更新版14393中战地4游戏窗口消失怎么办?
-
oracle expdp作业外表报错ORA-20011&KUP-11024&ORA-29913实例
-
健康饮食食谱一周吃什么,健康合理营养搭配!
-
索尼20周年纪念版灰白色PS4开箱图赏
-
小米10400mAh土豪金移动电源一周年特别纪念版图赏
-
Win10一周年更新14393.693累积更新补丁KB3213986更新失败的解决方法