numpy和matploptlib
numpy
Numpy介绍
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。 一个用python实现的科学计算,包括:1、一个强大的N维数组对象Array;2、比较成熟的(广播)函数库;3、用于整合C/C++和Fortran代码的工具包;4、实用的线性代数、傅里叶变换和随机数生成函数。numpy和稀疏矩阵运算包scipy配合使用更加方便。 NumPy(Numeric Python)提供了许多高级的数值编程工具,如:矩阵数据类型、矢量处理,以及精密的运算库。数据类型ndarray
编辑 NumPy provides an N-dimensional array type, the ndarray, which describes a collection of “items” of the same type. NumPy提供了一个 N维数组类型ndarray,它描述了 相同类型的“items”的集合。 ndarray到底跟原生python列表的区别:
从图中我们可以看出ndarray在存储数据的时候,数据与数据的地址都是连续的,这样就给使得批量操作数组元素时速度更快。 这是因为ndarray中的所有元素的类型都是相同的,而Python列表中的元素类型是任意的,所以ndarray在存储元素时内存可以连续,而python原生list就只能通过寻址方式找到下一个元素,这虽然也导致了在通用性能方面Numpy的ndarray不及Python原生list,但在科学计算中,Numpy的ndarray就可以省掉很多循环语句,代码使用方面比Python原生list简单的多。
numpy内置了并行运算功能,当系统有多个核心时,做某种计算时,numpy会自动做并行计算。
Numpy底层使用C语言编写,内部解除了GIL(全局解释器锁),其对数组的操作速度不受Python解释器的限制,效率远高于纯Python代码。
ndarray的属性:
生成数组的方法: empty(shape[, dtype, order]) empty_like(a[, dtype, order, subok]) eye(N[, M, k, dtype, order]) identity(n[, dtype])
ones
(shape[, dtype, order]) ones_like(a[, dtype, order, subok])
zeros
(shape[, dtype, order]) zeros_like(a[, dtype, order, subok]) full(shape, fill_value[, dtype, order]) full_like(a, fill_value[, dtype, order, subok])
Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形。
- 中文名
- 绘图库
- 外文名
- Matplotlib
- 所属领域
- 计算机
- 作 用
- 绘图
- 元 素
- x轴和y轴
import numpy as np import matplotlib.pyplot as plt import matplotlib matplotlib.rcParams['font.family']='SimHei' matplotlib.rcParams['font.sans-serif']=['SimHei'] labels=np.array(['第一次作业','第二次作业','第三次作业','第四次作业','第五次作业','第六次作业','第七次作业']) nAttr=7 data=np.array([0,0.909,1,1,1,0.875,0]) angles=np.linspace(0,2*np.pi,nAttr,endpoint=False) data=np.concatenate((data,[data[0]])) angles=np.concatenate((angles,[angles[0]])) fig=plt.figure(facecolor='white') plt.subplot(111,polar=True) plt.plot(angles,data,'bo-',color='g',linewidth=2) plt.fill(angles,data,facecolor='r',alpha=0.25) plt.thetagrids(angles*180/np.pi,labels) plt.figtext(0.52,0.95,'01我的成绩',ha='center') plt.grid(True) plt.savefig('xuexi.JPG') plt.show()
结果图:
更多精彩

