• 深度学习必备Python基础知识充电3


    1. 小引

    1.1 问题的出现

    在深度学习的实现过程中,经常会出现数组矩阵的计算

    1.2 解决

    NumPy的数组类提供了很多边界的方法, 在实现深度学习的过程中是非常方便的

    1.3 介绍

    NumPy是外部类

    指的是不包含在标准版的python中,首先需要导入NumPy库

    # 来试一下年轻人的第一个NumPy库
    
    import numpy as np # 导入的时候顺便给他起个别名
    
    • 1
    • 2
    • 3

    2. NumPy数组

    2.2 生成NumPy数组

    # 来试一下年轻人的第一个NumPy库
    import numpy as np
    
    x = np.array([1.2, 2.0, 3.0]) 
    print(x)
    print(type(x))
    
    D:\ANACONDA\envs\pytorch\python.exe C:/Users/Administrator/Desktop/Code/learn_pytorch/first_demo.py
    [1.2 2.  3. ]
    <class 'numpy.ndarray'>
    
    Process finished with exit code 0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    注意:在写代码的过程中
    方法的参数含义可能会记不清

    • 按一下Ctrl+P来进行查看
    • 有默认值的就不管了
    • 没有默认值的就自己写

    终极大法:看程序源码!

    2.2 NumPy数组运算【数组不就是一维向量吗?!

    size运算的实现

    # 来试一下年轻人的第一个NumPy库
    import numpy as np
    
    x = np.array([1.0, 2.0, 3.0])
    # print(x)
    # print(type(x))
    
    y = np.array([2, 4, 6])
    
    # 加法运算
    print(x + y)
    # 减法运算
    print(x - y)
    # 乘法运算
    print(x * y)
    # 除法运算
    print(x / y)
    
    D:\ANACONDA\envs\pytorch\python.exe C:/Users/Administrator/Desktop/Code/learn_pytorch/first_demo.py
    [3. 6. 9.]
    [-1. -2. -3.]
    [ 2.  8. 18.]
    [0.5 0.5 0.5]
    
    Process finished with exit code 0
    
    
    • 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

    2.3 数乘运算

    print(2*x)
    也是可以实现的

    3. 专业英语1

    element-wise 对应元素的

  • 相关阅读:
    【Angular1】基础使用及各类方法
    使用tailwindcss轻松实现移动端rem适配
    Unity中Shader反射环境
    ssh连接远程服务器,并在终端安装anaconda
    RabbitMQ 安装和使用Demo
    现代密码学 - 知识点汇总
    搭建hadoop集群
    国内常用的代理ip形式数据中心代理ip和静态住宅代理IP有什么区别
    认识WebSocket 以及怎么使用WebSocket
    hash表
  • 原文地址:https://blog.csdn.net/weixin_44943389/article/details/127878692