深度学习之绘图基础

文章目录

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

结果图片

相关推荐
紫金修道4 小时前
【DeepAgent】概述
开发语言·数据库·python
书到用时方恨少!4 小时前
Python multiprocessing 使用指南:突破 GIL 束缚的并行计算利器
开发语言·python·并行·多进程
Warson_L4 小时前
Python 常用内置标准库
python
Warson_L5 小时前
Python 函数的艺术 (Functions)
python
Warson_L5 小时前
Python 流程控制与逻辑
后端·python
long_songs5 小时前
手柄键盘映射器【github链接见文末 】
python·游戏·计算机外设·pygame·软件推荐·手柄映射键盘
必然秃头5 小时前
Python 环境安装及项目构建指南
python
Warson_L5 小时前
Python 四大组合数据类型 (Collection Types)
后端·python
廋到被风吹走5 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
Warson_L5 小时前
Python 数据类型核心笔记
python