赞
踩
强大的多维度数组与矩阵计算库
支持大量的维度数组与矩阵运算
几乎所有从事 Python 工作的 BI 和 AI 程序员都要使用 NumPy的强大功能
第一种:Anaconda 自带 NumPy 库,不需要安装(Anaconda的教程请点击查看)
第二种:使用 pip install numpy 命令安装
导入 numpy 库
- # 数据分析“三剑客”
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
查看 numpy 版本
- # 版本np.__version__
- # 执行结果'1.24.3'
- # python.png
- # 图片:其实是数字组成的,三维数组
- # RGB:红Red,绿Green,蓝Blue
- # RGB范围:0-255
- # plt.imread:读取图片的数据
- pyimg = plt.imread("python.png")
- pyimg
- # 执行结果
- array([[[0.09019608, 0.15294118, 0.24313726, 1. ],
- [0.05882353, 0.12156863, 0.21176471, 1. ],
- [0.08235294, 0.14509805, 0.23529412, 1. ],
- ...,
- [0.05490196, 0.11764706, 0.20784314, 1. ],
- [0.05098039, 0.11372549, 0.20392157, 1. ],
- [0.08235294, 0.14509805, 0.23529412, 1. ]],
-
- [[0.09019608, 0.15294118, 0.24313726, 1. ],
- [0.05882353, 0.12156863, 0.21176471, 1. ],
- [0.08235294, 0.14509805, 0.23529412, 1. ],
- ...,
- [0.05490196, 0.11764706, 0.20784314, 1. ],
- [0.05098039, 0.11372549, 0.20392157, 1. ],
- [0.08235294, 0.14509805, 0.23529412, 1. ]],
-
- [[0.09019608, 0.15294118, 0.24313726, 1. ],
- [0.05882353, 0.12156863, 0.21176471, 1. ],
- [0.08235294, 0.14509805, 0.23529412, 1. ],
- ...,
- [0.05490196, 0.11764706, 0.20784314, 1. ],
- [0.05098039, 0.11372549, 0.20392157, 1. ],
- [0.08235294, 0.14509805, 0.23529412, 1. ]],
-
- ...,
-
- [[0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- ...,
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ]],
-
- [[0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- ...,
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ]],
-
- [[0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- ...,
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ],
- [0.0627451 , 0.25882354, 0.5294118 , 1. ]]], dtype=float32)
-
- type(pyimg)
- # numpy.ndarray:多维数组
- # nd:n维度,多维
- # array:数组
- # 执行结果
- numpy.ndarray
-
- # 查看形状:三维
- # (539, 1080, 4):高度、宽度、颜色(RGB的值)
- pyimg.shape
- # 执行结果
- (539, 1080, 4)
-
- # 显示图片
- plt.imshow(pyimg)
-
- # 图片:3维数据(彩色),2维数据是白色
- # 视频:4维数据(x,539, 1080, 4)
- # 数据分析:一切皆数据,一切皆矩阵
- # Python:一切皆对象
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。