作者:吉光大大
(服务器到期,在此备份blog)
注意: 对于文件操作,因为存在路径访问问题,必须按照以下步骤执行操作,否则可能导致评测不正确。
首先执行以下单元格内容,即
from setup import path,abspath
对于任何涉及文件读写的代码,必须以“f’{path}/相对路径’”的方式访问。参考以下示例。示例中的文件读写方式可以自由改变,但是文件路径必须按照指定方式书写。
例1:打开同目录下test.txt文件
with open(f’{path}/test.txt’,‘w’,encoding=‘utf8’) as f:
或者
filename = ‘test.txt’
with open(abspath(filename),‘w’,encoding=‘utf8’) as f:
例2:如需要打开同目录下code子文件夹下的a.txt
from pathlib import Path
file = Path(f’{path}/code/a.txt’)
或者
file = Path(abspath(‘code/a.txt’))
1、 绘制以下四个函数及对应导数的函数图形。x轴从-5到5,步长为0.2;y轴自动设置。4行2列8个图,同列共享x轴。
- Figure的名称必须为fig1
- 不要使用plt.show, 会导致保存图像不正确。
- e x e^x ex 采用np.exp()函数
- 所有数值保持小数点后6位精度
样例:
# TODO Add your code here
# x = np.round(np.linspace(-5,5,50,endpoint=False),6)
x = np.round(np.arange(-5,5,0.2),6)
# print(x)
fig1,ax1= plt.subplots(4,2,sharex = True)
# plt.suptitle("fig1")
F1 = np.round(1 / (1 + np.exp(-x)),6)
f1 = np.round(F1 * (1 - F1),6)
F2 = np