码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 深度学习笔记之微积分及绘图


    深度学习笔记之微积分及绘图

    学习资料来源:微积分

    %matplotlib inline
    from matplotlib_inline import backend_inline
    from mxnet import np, npx
    from d2l import mxnet as d2l
    
    npx.set_np()
    
    def f(x):
    	return 3 * x ** 2 - 4 * x
    
    def numerical_lim(f, x, h):
    	return (f(x + h) - f(x)) / h
    
    h = 0.1 
    for i in range(5):
    	print(f'h={h:.5f}, numerical limit={numerical_lim(f, 1, h):.5f}')
    	h *= 0.1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    在这里插入图片描述

    def use_svg_display():
    	"""使用svg格式在Jupyter中显示绘图"""
    	backend_inline.set_matplotlib_formats('svg')
    
    def set_figsize(figsize=(3.5, 2.5)):
    	"""设置matplotlib的图表大小"""
    	use_svg_display()
    	d2l.plt.rcParams['figure.figsize'] = figsize
    	
    # set_axes函数用于设置matplotlib生成图表的轴的属性
    def set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend):
    	"""这是matplotlib的轴"""
    	axes.set_xlabel(xlabel)
    	axes.set_ylabel(ylabel)
    	axes.set_xscale(xscale)
    	axes.set_yscale(yscale)
    	axes.set_xlim(xlim)
    	axes.set_ylim(ylim)
    	if legend:
    		axes.legend(legend)
    	axes.grid()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    通过use_svg_display()、set_figsize()、set_axes()用于图形配置的函数,定义plot函数来绘制曲线

    def plot(X, Y=None, xlabel=None, ylabel=None, legend=None, xlim=None,
             ylim=None, xscale='linear', yscale='linear',
             fmts=('-', 'm--', 'g-.', 'r:'), figsize=(3.5, 2.5), axes=None):
        """绘制数据点"""
        if legend is None:
            legend = []
    
        set_figsize(figsize)
        axes = axes if axes else d2l.plt.gca()
    
        # 如果X有一个轴,输出True
        def has_one_axis(X):
            return (hasattr(X, "ndim") and X.ndim == 1 or isinstance(X, list)
                    and not hasattr(X[0], "__len__"))
    
        if has_one_axis(X):
            X = [X]
        if Y is None:
            X, Y = [[]] * len(X), X
        elif has_one_axis(Y):
            Y = [Y]
        if len(X) != len(Y):
            X = X * len(Y)
        axes.cla()
        for x, y, fmt in zip(X, Y, fmts):
            if len(x):
                axes.plot(x, y, fmt)
            else:
                axes.plot(y, fmt)
        set_axes(axes, xlabel, ylabel, xlim, ylim, xscale, yscale, legend)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    # 绘制函数u=f(x)及其在x=1处的切线y=2x-3,其中系数2是切线的斜率
    x = np.arange(0, 3, 0.1)
    plot(x, [f(x), 2 * x - 3], 'x', 'f(x)', legend=['f(x)', 'Tangent line (x=1)'])
    
    • 1
    • 2
    • 3

    在这里插入图片描述
    练习:在这里插入图片描述

    在这里插入图片描述

  • 相关阅读:
    Windows 0x80190001错误登录失败
    G1D5-Intriguing properties of neural networks
    每日一题:vue3自定义指令大全(呕心沥血所作,附可运行项目源码)
    实体店引流客户的最快方法是什么?线上短视频+直播引流!
    ant.design 的 Pro Component 的 ProTable 清除表单内容的方法
    使用标准信号检测 VM振弦采集模块测量精度
    智慧农业:农林牧数据可视化监控平台
    springboot和vue:二、springboot特点介绍+热部署热更新
    day 2 | 977.有序数组的平方 ,209.长度最小的子数组 ,59.螺旋矩阵II
    Uknow | 优维低代码:Custom Processors 自定义加工函数
  • 原文地址:https://blog.csdn.net/qq_43627631/article/details/133520611
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号