Python数据分析第10章 SciPy科学计算基础
Python数据分析 第10章 SciPy科学计算基础
第 10 章 SciPy科学计算基础·Scipy是一款用于数学、科学和工程领域的Python工具包,可以处理插值、积分、优化、图像处理、常微分方程数值解的求解、信号处理等问题
第 10 章 SciPy科学计算基础 • Scipy是一款用于数学、科学和工程领域的Python工具包, 可以处理插值、积分、优化、图像处理、常微分方程数值 解的求解、信号处理等问题
10.1 SciPy中的常数与特殊函数1SciPy的constants模块·SciPy的constants模块包含了大量用于科学计算的常数【例10-1】显示constants模块中的常用常数。In[1]from scipyimport constantsas Cprint(C.pi)#圆周率print(C.golden)#黄金比例print(C.c)#真空中的光速print(C.h)#普朗克常数print(C.mile)#一英里等于多少米print(C.inch)#一英寸等于多少米print(C.degree)#一度等于多少弧度print(C.minute)#一分钟等于多少秒print(C.g)#标准重力加速度
10.1 SciPy中的常数与特殊函数 • 1 SciPy的constants模块 • SciPy的constants模块包含了大量用于科学计算的常数。 In[1] from scipy import constants as C print(C.pi) #圆周率 print(C.golden) #黄金比例 print(C.c) #真空中的光速 print(C.h) #普朗克常数 print(C.mile) #一英里等于多少米 print(C.inch) #一英寸等于多少米 print(C.degree) #一度等于多少弧度 print(C.minute) #一分钟等于多少秒 print(C.g) #标准重力加速度 【例10-1】显示constants模块中的常用常数
·2 SciPy的special模块SciPy的special模块包含了大量函数库,包括基本数学函数、特殊函数以及NumPy中的所有函数。from scipy import special as Sprint(S.cbrt(8))#立方根【例10-2】print(S.exp10(3)) #10**3special模块中print(S.sindg(90))#正弦函数,参数为角度的常用函数。print(S.round(3.1))#四舍五入函数print(S.round(3.5))print(S.round(3.499)print(S.comb(5,3))#从5个中任选3个的组合数print(S.perm(5,3))#排列数print(S.gamma(4))#gamma函数print(S.beta(10,200))#beta函数print(S.sinc(O))#sinc函数
• 2 SciPy的special模块 • SciPy的special模块包含了大量函数库,包括基本数学函数、特殊函 数以及NumPy中的所有函数。 【例10-2】 special模块中 的常用函数。 from scipy import special as S print(S.cbrt(8)) #立方根 print(S.exp10(3)) #10**3 print(S.sindg(90)) #正弦函数,参数为角度 print(S.round(3.1)) #四舍五入函数 print(S.round(3.5)) print(S.round(3.499)) print(S.comb(5,3)) #从5个中任选3个的组合数 print(S.perm(5,3)) #排列数 print(S.gamma(4)) #gamma函数 print(S.beta(10,200)) #beta函数 print(S.sinc(0)) #sinc函数
10.2 SciPy中的线性代数运算SciPy.linalg是SciPy中实现线性代数计算的模块,常用的导入方式为:from scipy import linalg在NumPy中,矩阵有矩阵类型和二维数组两种表示方法(1)数组类型下的基本操作矩阵类型数据可以用np.mat()或mat.matrix创建。【例10-3】矩阵的创建及其简单运算。from scipy import linalgimportnumpyas npA = np.mat([1,2;3,4])print(A矩阵为:In',A)print(A的转置矩阵为:n,A.T)print(A的逆矩阵为:In',A.I)
10.2 SciPy中的线性代数运算 • SciPy.linalg是SciPy中实现线性代数计算的模块,常用的导入方式为: from scipy import linalg 在NumPy中,矩阵有矩阵类型和二维数组两种表示方法。 (1)数组类型下的基本操作 矩阵类型数据可以用np.mat()或mat.matrix()创建。 【例10-3】矩阵的创建及其简单运算。 from scipy import linalg import numpy as np A = np.mat('[1,2;3,4]') print('A矩阵为:\n',A) print('A的转置矩阵为:\n',A.T) print('A的逆矩阵为:\n',A.I)