没有合适的资源?快使用搜索试试~ 我知道了~
首页Scipy Tutorial(Scipy教程)
Scipy Tutorial(Scipy教程)
需积分: 50 65 下载量 116 浏览量
更新于2023-03-16
评论 5
收藏 31.72MB PDF 举报
scipy包含致力于科学计算中常见问题的各个工具箱。它的不同子模块相应于不同的应用。像插值,积分,优化,图像处理,统计,特殊函数等等。 scipy可以与其它标准科学计算程序库进行比较,比如GSL(GNU C或C++科学计算库),或者Matlab工具箱。scipy是Python中科学计算程序的核心包; 它用于有效地计算numpy矩阵,来让numpy和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页未读,继续阅读
快乐的小马甲
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- 27页智慧街道信息化建设综合解决方案.pptx
- 计算机二级Ms-Office选择题汇总.doc
- 单链表的插入和删除实验报告 (2).docx
- 单链表的插入和删除实验报告.pdf
- 物联网智能终端项目设备管理方案.pdf
- 如何打造品牌的模式.doc
- 样式控制与页面布局.pdf
- 武汉理工Java实验报告(二).docx
- 2021线上新品消费趋势报告.pdf
- 第3章 Matlab中的矩阵及其运算.docx
- 基于Web的人力资源管理系统的必要性和可行性.doc
- 基于一阶倒立摆的matlab仿真实验.doc
- 速运公司物流管理模式研究教材
- 大数据与管理.pptx
- 单片机课程设计之步进电机.doc
- 大数据与数据挖掘.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0