Scipy简介

Scipy科学计算库详解

Scipy简介

  • Scipy依赖于Numpy
  • Scipy包含的功能:最优化、线性代数、积分、插值、拟合、特殊函数、快速傅里叶变换、信号处理、图像处理、常微分方程求解器等
  • 应用场景:Scipy是高端科学计算工具包,用于数学、科学、工程学等领域
  • Scipy由一些特定功能的子模块组成:
    在这里插入图片描述

图片消噪处理

  • scipy.fftpack模块用来计算快速傅里叶变换
    速度比传统傅里叶变换更快,是对之前算法的改进
    图片是二维数据,注意使用fftpack的二维转变方法
from scipy.fftpack import fft2, ifft2
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
#读取照片数据
moon = plt.imread('moonlanding.png')	==>
array([[ 0.04705882,  0.        ,  0.23921569, ...,  0.        ,
         0.00392157,  0.53333336],
       [ 0.        ,  0.        ,  0.67843139, ...,  0.10196079,
         0.29019609,  0.        ],
       [ 0.72156864,  0.10980392,  0.60392159, ...,  0.        ,
         0.21568628,  1.        ],
       ..., 
       [ 0.00392157,  0.        ,  1.        , ...,  1.        ,
         1.        ,  0.95686275],
       [ 0.        ,  0.        ,  0.15686275, ...,  0.        ,
         0.        ,  0.35294119],
       [ 1.        ,  0.52156866,  0.04705882, ...,  0.        ,
         0.        ,  1.        ]], dtype=float32
#数据形式 
moon.shape		==> (474, 630)
#展示图片
plt.imshow(moon, cmap='gray')
#cmap 指定RGB的Z值,如果是三维数组则忽略cmap值
# 可选择的颜色映射参数为:Accent, Accent_r, Blues, Blues_r, BrBG, BrBG_r, BuGn, BuGn_r, BuPu, BuPu_r, CMRmap, CMRmap_r, Dark2, Dark2_r, GnBu, GnBu_r, Greens, Greens_r, Greys, Greys_r, OrRd, OrRd_r, Oranges, Oranges_r, PRGn, PRGn_r, Paired, Paired_r, Pastel1, Pastel1_r, Pastel2, Pastel2_r, PiYG, PiYG_r, PuBu, PuBuGn, PuBuGn_r, PuBu_r, PuOr, PuOr_r, PuRd, PuRd_r, Purples, Purples_r, RdBu, RdBu_r, RdGy, RdGy_r, RdPu, RdPu_r, RdYlBu, RdYlBu_r, RdYlGn, RdYlGn_r, Reds, Reds_r, Set1, Set1_r, Set2, Set2_r, Set3, Set3_r, Spectral, Spectral_r, Vega10, Vega10_r, Vega20, Vega20_r, Vega20b, Vega20b_r, Vega20c, Vega20c_r, Wistia, Wistia_r, YlGn, YlGnBu, YlGnBu_r, YlGn_r, YlOrBr, YlOrBr_r, YlOrRd, YlOrRd_r, afmhot, afmhot_r, autumn, autumn_r, binary, binary_r, bone, bone_r, brg, brg_r, bwr, bwr_r, cool, cool_r, coolwarm, coolwarm_r, copper, copper_r, cubehelix, cubehelix_r, flag, flag_r, gist_earth, gist_earth_r, gist_gray, gist_gray_r, gist_heat, gist_heat_r, gist_ncar, gist_ncar_r, gist_rainbow, gist_rainbow_r, gist_stern, gist_stern_r, gist_yarg, gist_yarg_r, gnuplot, gnuplot2, gnuplot2_r, gnuplot_r, gray, gray_r, hot, hot_r, hsv, hsv_r, inferno, inferno_r, jet, jet_r, magma, magma_r, nipy_spectral, nipy_spectral_r, ocean, ocean_r, pink, pink_r, plasma, plasma_r, prism, prism_r, rainbow, rainbow_r, seismic, seismic_r, spectral, spectral_r, spring, spring_r, summer, summer_r, tab10, tab10_r, tab20, tab20_r, tab20b, tab20b_r, tab20c, tab20c_r, terrain, terrain_r, viridis, viridis_r, winter, winter_r


# 傅里叶变换消噪

# 把时域空间转换到频域空间
f_moon = fft2(moon)

05-09
### SciPy简介 SciPy 是一个基于 Python 的开源科学计算库,它建立在 NumPy 之上并扩展了其功能SciPy 提供了许多用于数值积分、优化、插值、傅里叶变换和其他科学计算任务的模块[^1]。 以下是关于如何安装和使用 SciPy 的一些基本指导: #### 安装 SciPy 要安装 SciPy,可以使用 `pip` 或者 Anaconda 来完成。推荐的方式如下所示: ```bash pip install scipy ``` 如果你正在使用 Anaconda,则可以通过以下命令来安装: ```bash conda install scipy ``` #### 使用 SciPy 进行科学计算 下面是一些常见的 SciPy 功能及其对应的子模块说明: ##### 数值积分 (scipy.integrate) 通过 `scipy.integrate.quad()` 函数实现一维定积分的功能。 ```python from scipy import integrate result, error = integrate.quad(lambda x: x**2, 0, 1) print(result) # 输出结果应接近于 1/3 ``` ##### 插值 (scipy.interpolate) 利用 `scipy.interpolate.interp1d()` 可以创建线性或者高阶多项式的插值函数。 ```python import numpy as np from scipy import interpolate x = np.linspace(0, 10, num=11, endpoint=True) y = np.cos(-x**2 / 9.0) f = interpolate.interp1d(x, y, kind='cubic') new_x = np.linspace(0, 10, num=41, endpoint=True) new_y = f(new_x) ``` ##### 线性代数操作 (scipy.linalg) 相比 NumPy 中的基础矩阵运算,`scipy.linalg` 提供更全面且高效的线性代数工具集。 ```python from scipy import linalg A = np.array([[1, 2], [3, 4]]) b = np.array([5, 6]) solution = linalg.solve(A, b) print(solution) # 解方程 Ax=b ``` ##### 统计分析 (scipy.stats) 提供广泛的统计分布以及测试方法。 ```python from scipy import stats rvs = stats.norm.rvs(loc=0, scale=1, size=1000) mean_value = rvs.mean() std_deviation = rvs.std(ddof=1) ``` #### 文档资源链接 官方文档提供了详尽的例子和技术细节,强烈建议查阅:https://docs.scipy.org/doc/scipy/ --- ### 注意事项 为了能够高效地运用 SciPy 编写性能良好的代码,熟悉 NumPy 是非常必要的,因为它构成了 SciPy 数据结构的核心部分。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值