前言
NumPy(Numerical Python)是 Python 的一种开源的数值计算扩展。这种工具可用来存储和处理大型矩阵,比 Python 自身的嵌套列表(nested list structure)结构要高效的多(该结构也可以用来表示矩阵(matrix)),支持大量的维度数组与矩阵运算,此外也针对数组运算提供大量的数学函数库。NumPy 通常与SciPy(Scientific Python)和 Matplotlib(绘图库)一起使用, 这种组合广泛用于替代 MatLab,是一个强大的科学计算环境,有助于我们通过 Python 学习数据科学或者机器学习。
一、安装
pip 安装 NumPy 命令:
pip install numpy #(使用境外源)
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple #(使用国内的镜像源)
from numpy import *
print(eye(4))
'''
打印4*4对角矩阵
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
'''
总结
NumPy 官网 :http://www.numpy.org/
NumPy 源代码:https://github.com/numpy/numpy