当前位置:   article > 正文

手把手教你安装和使用NumPy库_numpy库怎么安装

numpy库怎么安装

1.NumPy

  • 强大的多维度数组与矩阵计算库

  • 支持大量的维度数组与矩阵运算

  • 几乎所有从事 Python 工作的 BI 和 AI 程序员都要使用 NumPy的强大功能

2.安装 NumPy 库

3.导入 numpy 库,并查看numpy版本

  • 导入 numpy 库

  1. # 数据分析“三剑客”
  2. import numpy as np
  3. import pandas as pd
  4. import matplotlib.pyplot as plt
  • 查看 numpy 版本

  1. # 版本np.__version__
  2. # 执行结果'1.24.3'

4.matplotlib 操作图片

  1. # python.png
  2. # 图片:其实是数字组成的,三维数组
  3. # RGB:红Red,绿Green,蓝Blue
  4. # RGB范围:0-255
  5. # plt.imread:读取图片的数据
  6. pyimg = plt.imread("python.png")
  7. pyimg
  8. # 执行结果
  9. array([[[0.09019608, 0.15294118, 0.24313726, 1. ],
  10. [0.05882353, 0.12156863, 0.21176471, 1. ],
  11. [0.08235294, 0.14509805, 0.23529412, 1. ],
  12. ...,
  13. [0.05490196, 0.11764706, 0.20784314, 1. ],
  14. [0.05098039, 0.11372549, 0.20392157, 1. ],
  15. [0.08235294, 0.14509805, 0.23529412, 1. ]],
  16. [[0.09019608, 0.15294118, 0.24313726, 1. ],
  17. [0.05882353, 0.12156863, 0.21176471, 1. ],
  18. [0.08235294, 0.14509805, 0.23529412, 1. ],
  19. ...,
  20. [0.05490196, 0.11764706, 0.20784314, 1. ],
  21. [0.05098039, 0.11372549, 0.20392157, 1. ],
  22. [0.08235294, 0.14509805, 0.23529412, 1. ]],
  23. [[0.09019608, 0.15294118, 0.24313726, 1. ],
  24. [0.05882353, 0.12156863, 0.21176471, 1. ],
  25. [0.08235294, 0.14509805, 0.23529412, 1. ],
  26. ...,
  27. [0.05490196, 0.11764706, 0.20784314, 1. ],
  28. [0.05098039, 0.11372549, 0.20392157, 1. ],
  29. [0.08235294, 0.14509805, 0.23529412, 1. ]],
  30. ...,
  31. [[0.0627451 , 0.25882354, 0.5294118 , 1. ],
  32. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  33. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  34. ...,
  35. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  36. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  37. [0.0627451 , 0.25882354, 0.5294118 , 1. ]],
  38. [[0.0627451 , 0.25882354, 0.5294118 , 1. ],
  39. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  40. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  41. ...,
  42. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  43. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  44. [0.0627451 , 0.25882354, 0.5294118 , 1. ]],
  45. [[0.0627451 , 0.25882354, 0.5294118 , 1. ],
  46. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  47. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  48. ...,
  49. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  50. [0.0627451 , 0.25882354, 0.5294118 , 1. ],
  51. [0.0627451 , 0.25882354, 0.5294118 , 1. ]]], dtype=float32)
  52. type(pyimg)
  53. # numpy.ndarray:多维数组
  54. # nd:n维度,多维
  55. # array:数组
  56. # 执行结果
  57. numpy.ndarray
  58. # 查看形状:三维
  59. # (539, 1080, 4):高度、宽度、颜色(RGB的值)
  60. pyimg.shape
  61. # 执行结果
  62. (539, 1080, 4)
  63. # 显示图片
  64. plt.imshow(pyimg)
  65. # 图片:3维数据(彩色),2维数据是白色
  66. # 视频:4维数据(x,539, 1080, 4)
  67. # 数据分析:一切皆数据,一切皆矩阵
  68. # Python:一切皆对象

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/968829
推荐阅读
相关标签
  

闽ICP备14008679号