没有合适的资源?快使用搜索试试~ 我知道了~
首页Python Scipy 实例教程
Python Scipy 实例教程
2星 需积分: 46 59 下载量 73 浏览量
更新于2023-05-30
1
收藏 31.38MB PDF 举报
系统性学习python Scipy包的一个很好的文档,文档并非追求大而全,而是将常用的功能进行了描述,有图有代码。
资源详情
资源推荐
Python
Matplotlib
SciKits
Numpy
SciPy
IPython
IP[y]:
Cython
2017
EDITION
Edited by
Gaël Varoquaux
Emmanuelle Gouillart
Olaf Vahtras
Scipy
Lecture Notes
www.scipy-lectures.org
Gaël Varoquaux • Emmanuelle Gouillart • Olav Vahtras
Christopher Burns • Adrian Chauve • Robert Cimrman • Christophe Combelles
Pierre de Buyl • Ralf Gommers • André Espaze • Zbigniew Jędrzejewski-Szmek
Valentin Haenel • Gert-Ludwig Ingold • Fabian Pedregosa • Didrik Pinte
Nicolas P. Rougier • Pauli Virtanen
and many others...
Contents
I Getting started with Python for science 2
1 Python scientific computing ecosystem 4
1.1 Why Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 The Scientific Python ecosystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 Before starting: Installing a working environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4 The workflow: interactive environments and text editors . . . . . . . . . . . . . . . . . . . . . . . . 8
2 The Python language 12
2.1 First steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Basic types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Control Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.4 Defining functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.5 Reusing code: scripts and modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.6 Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.7 Standard Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
2.8 Exception handling in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.9 Object-oriented programming (OOP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3 NumPy: creating and manipulating numerical data 47
3.1 The NumPy array object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.2 Numerical operations on arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.3 More elaborate arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.4 Advanced operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.5 Some exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.6 Full code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4 Matplotlib: plotting 97
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
4.2 Simple plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.3 Figures, Subplots, Axes and Ticks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
4.4 Other Types of Plots: examples and exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
4.5 Beyond this tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.6 Quick references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
4.7 Full code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
5 Scipy : high-level scientific computing 184
5.1 File input/output: scipy.io . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
5.2 Special functions: scipy.special . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
5.3 Linear algebra operations: scipy.linalg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
i
5.4 Interpolation: scipy.interpolate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
5.5 Optimization and fit: scipy.optimize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
5.6 Statistics and random numbers: scipy.stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
5.7 Numerical integration: scipy.integrate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
5.8 Fast Fourier transforms: scipy.fftpack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
5.9 Signal processing: scipy.signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
5.10 Image manipulation: scipy.ndimage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
5.11 Summary exercises on scientific computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
5.12 Full code examples for the scipy chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
6 Getting help and finding documentation 259
II Advanced topics 262
7 Advanced Python Constructs 264
7.1 Iterators, generator expressions and generators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
7.2 Decorators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
7.3 Context managers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
8 Advanced NumPy 281
8.1 Life of ndarray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
8.2 Universal functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
8.3 Interoperability features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
8.4 Array siblings: chararray, maskedarray, matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
8.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
8.6 Contributing to NumPy/Scipy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
9 Debugging code 314
9.1 Avoiding bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
9.2 Debugging workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
9.3 Using the Python debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
9.4 Debugging segmentation faults using gdb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
10 Optimizing code 325
10.1 Optimization workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
10.2 Profiling Python code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
10.3 Making code go faster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
10.4 Writing faster numerical code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
11 Sparse Matrices in SciPy 332
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
11.2 Storage Schemes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
11.3 Linear System Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
11.4 Other Interesting Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
12 Image manipulation and processing using Numpy and Scipy 352
12.1 Opening and writing to image files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
12.2 Displaying images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
12.3 Basic manipulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
12.4 Image filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
12.5 Feature extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
12.6 Measuring objects properties: ndimage.measurements . . . . . . . . . . . . . . . . . . . . . . . . 366
12.7 Full code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
12.8 Examples for the image processing chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
13 Mathematical optimization: finding minima of functions 397
13.1 Knowing your problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
13.2 A review of the different optimizers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
13.3 Full code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
13.4 Examples for the mathematical optimization chapter . . . . . . . . . . . . . . . . . . . . . . . . . . 406
ii
13.5 Practical guide to optimization with scipy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
13.6 Special case: non-linear least-squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
13.7 Optimization with constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
13.8 Full code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
13.9 Examples for the mathematical optimization chapter . . . . . . . . . . . . . . . . . . . . . . . . . . 438
14 Interfacing with C 439
14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
14.2 Python-C-Api . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
14.3 Ctypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
14.4 SWIG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
14.5 Cython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
14.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
14.7 Further Reading and References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
14.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
III Packages and applications 460
15 Statistics in Python 462
15.1 Data representation and interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
15.2 Hypothesis testing: comparing two groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
15.3 Linear models, multiple factors, and analysis of variance . . . . . . . . . . . . . . . . . . . . . . . . 471
15.4 More visualization: seaborn for statistical exploration . . . . . . . . . . . . . . . . . . . . . . . . . . 476
15.5 Testing for interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
15.6 Full code for the figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
15.7 Solutions to this chapter’s exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
16 Sympy : Symbolic Mathematics in Python 505
16.1 First Steps with SymPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
16.2 Algebraic manipulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
16.3 Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
16.4 Equation solving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
16.5 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
17 Scikit-image: image processing 513
17.1 Introduction and concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
17.2 Input/output, data types and colorspaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
17.3 Image preprocessing / enhancement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
17.4 Image segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
17.5 Measuring regions’ properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
17.6 Data visualization and interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
17.7 Feature extraction for computer vision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
17.8 Full code examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
17.9 Examples for the scikit-image chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
18 Traits: building interactive dialogs 538
18.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
18.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
18.3 What are Traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
19 3D plotting with Mayavi 557
19.1 Mlab: the scripting interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 558
19.2 Interactive work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
19.3 Slicing and dicing data: sources, modules and filters . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
19.4 Animating the data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
19.5 Making interactive dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
19.6 Putting it together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
20 scikit-learn: machine learning in Python 572
iii
20.1 Introduction: problem settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
20.2 Basic principles of machine learning with scikit-learn . . . . . . . . . . . . . . . . . . . . . . . . . . 577
20.3 Supervised Learning: Classification of Handwritten Digits . . . . . . . . . . . . . . . . . . . . . . . 582
20.4 Supervised Learning: Regression of Housing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
20.5 Measuring prediction performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
20.6 Unsupervised Learning: Dimensionality Reduction and Visualization . . . . . . . . . . . . . . . . 594
20.7 The eigenfaces example: chaining PCA and SVMs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
20.8 Parameter selection, Validation, and Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
20.9 Examples for the scikit-learn chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Index 652
iv
剩余656页未读,继续阅读
qq_40063752
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 京瓷TASKalfa系列维修手册:安全与操作指南
- 小波变换在视频压缩中的应用
- Microsoft OfficeXP详解:WordXP、ExcelXP和PowerPointXP
- 雀巢在线媒介投放策划:门户网站与广告效果分析
- 用友NC-V56供应链功能升级详解(84页)
- 计算机病毒与防御策略探索
- 企业网NAT技术实践:2022年部署互联网出口策略
- 软件测试面试必备:概念、原则与常见问题解析
- 2022年Windows IIS服务器内外网配置详解与Serv-U FTP服务器安装
- 中国联通:企业级ICT转型与创新实践
- C#图形图像编程深入解析:GDI+与多媒体应用
- Xilinx AXI Interconnect v2.1用户指南
- DIY编程电缆全攻略:接口类型与自制指南
- 电脑维护与硬盘数据恢复指南
- 计算机网络技术专业剖析:人才培养与改革
- 量化多因子指数增强策略:微观视角的实证分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功