深度学习之绘图基础

文章目录

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()

结果图片

相关推荐
曲幽8 小时前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户83562907805113 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon14 小时前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly14 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程14 小时前
一天一个Python库:pyarrow - 大规模数据处理的利器
python
Flittly16 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(4)Subagents (子智能体)
python·agent
明月_清风1 天前
Python 装饰器前传:如果不懂“闭包”,你只是在复刻代码
后端·python
明月_清风1 天前
打破“死亡环联”:深挖 Python 分代回收与垃圾回收(GC)机制
后端·python
ZhengEnCi2 天前
08c. 检索算法与策略-混合检索
后端·python·算法
明月_清风2 天前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python