深度学习之绘图基础

文章目录

1.实验目的

熟练绘制各种图像,为深度学习打基础

2. 需求

给定一个函数,需要你画出原图像以及这个函数在某点切线图像

3.代码

python 复制代码
# @File: python绘制函数图像以及倒数图像.py
# @Author: chen_song
# @Time: 2024/6/21 下午8:52

from matplotlib import pyplot as plt
import numpy as np

x = np.arange(0,2*np.pi,0.01)
y = [np.sin(x) for x in x]
plt.plot(x,y)
def getK(y, x):
    h = 1e-4
    return (getFunction(x + h) - getFunction(x)) / h

def getFunction(x):
    return np.sin(x)

k = getK(y, np.pi/4)
b = getFunction(1) - k
print(k,b)
y1 = [k * x + b for x in x]
plt.plot(x,y1)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.title('正弦函数及其在pi/4处切线图像')
plt.show()

结果图片

相关推荐
Warson_L7 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅7 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅7 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L7 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅8 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L8 小时前
python的类&继承
python
Warson_L8 小时前
类型标注/type annotation
python
ThreeS10 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵12 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏