Python官网上的发行版是不包含NumPy模块,需要用户自己安装。
1).查看是否已经安装过numpy
#查看pip的版本
C:\Users\Niu>pip -V
pip 23.3.1 from D:\Programs\Python\Python311\Lib\site-packages\pip (python 3.11)
C:\Users\Niu>pip list
Package Version
--------------------------------- ---------------
...
numpy 1.26.2
2.查看numpy的最新版本
C:\Users\Niu>pip show numpy
Name: numpy
Version: 1.26.2
Summary: Fundamental package for array computing in Python
Home-page: https://numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: Copyright (c) 2005-2023, NumPy Developers.
All rights reserved.
...
3).安装numpy
C:\Users\Niu>pip install numpy
4).我们也可以把与numpy紧密联系的其它常用库也顺便安装了,比如:scipy 和 matplotlib
C:\Users\Niu>pip3 install numpy scipy matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
#查看是否已经安装
C:\Users\Niu>pip list
Package Version
--------------------------------- ---------------
...
matplotlib 3.8.1
numpy 1.26.2
scipy 1.11.4
使用jupyter编程一段代码测试。
from numpy import *
#eye(4) 生成对角矩阵。
eye(4)
输出结果:
array([[1., 0., 0., 0.],
[0., 1., 0., 0.],
[0., 0., 1., 0.],
[0., 0., 0., 1.]])
matplotlib需要掌握的是: 1.散点图,折线图,条形图,直方图,饼状图,箱形图的绘制。 2.绘图的三大系统:pyplot,pylab(不推荐),面向对象。 3.坐标轴的调整,添加文字注释,区域填充,及特殊图形patches的使用。