scipy的基本操作

来源:互联网 发布:linux中export命令 编辑:程序博客网 时间:2024/05/23 15:49

插值:

import numpy as npfrom PIL import Imageimport matplotlib.pyplot as pltfrom scipy.interpolate import interp1dx=np.linspace(0,1,10) #x轴取0-1取10个数y=np.sin(2*np.pi*x) #函数y=sin(2*pi*x)#进行插值,会让曲线变得平滑很多li=interp1d(x,y,kind='cubic') #kind是插值类型x_new=np.linspace(0,1,50)y_new=li(x_new)plt.figure()plt.plot(x,y,"r") #红色显示原始数据plt.plot(x_new,y_new,"K") #黑色显示新数据plt.show()print (y_new)

Linear利用函数进行矩阵的分解

#coding=utf-8__author__ = 'mac'#Linear利用函数进行矩阵的分解from scipy import linalg as lgarr=np.array([[1,2],[3,4]])#用scipy和numpy处理线性矩阵是一样的print ("Det:",lg.det(arr)) #计算行列式print ("Inv:",lg.inv(arr)) #计算逆矩阵#用scipy解线性方程组b=np.array([6,14])print ("Sol:",lg.solve(arr,b)) #求另一因子print ("Eig:",lg.eig(arr))  #求特征值和特征向量#用scipy进行矩阵的分解比较容易。下面是几个矩阵的分解print ("LU:",lg.lu(arr)) #进行LU分解print ("QR:",lg.qr(arr)) #进行QR分解print ("SVD:",lg.svd(arr)) #进行奇异值分解print ("Schur:",lg.schur(arr)) #进行布尔分解
原创粉丝点击