没有合适的资源?快使用搜索试试~ 我知道了~
首页Guide to NumPy
资源详情
资源评论
资源推荐

Guide to NumPy
Travis E. Oliphant, PhD
Dec 7, 2006
This book is under restricted distribution using a Market-Determined, Tempo-
rary, Distribution-Restriction (MDTDR) system (see http://www.trelgo l.com) until
October 31, 2010 at the latest. If you receive this book, you are a sked not to c opy it
in any fo rm (electronic or paper) until the temporar y distribution-re striction lapses.
If you have multiple users at an institution, you should either share a single copy
using some form of digital library check-out, or buy multiple copies. The more
copies purchased, the sooner the documentation can be released from this incon-
venient distribution restriction. After October 31, 2010 this book may be freely
copied in any format and used as so urce material for other books as long as ac -
knowledgement of the original author is given. Your support of this temporary
distribution restriction plays an essential role in allowing the author and others like
him to produce mo re quality b ooks and software.
1

Contents
I NumPy from Python 12
1 Origins of NumPy 13
2 Object Essentials 18
2.1 Data-Type Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2 Basic indexing (slicing) . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Memory Layout of ndarray . . . . . . . . . . . . . . . . . . . . . . 26
2.3.1 Contiguous Memory Layout . . . . . . . . . . . . . . . . . . . 26
2.3.2 Non-contiguous memory layout . . . . . . . . . . . . . . . . . 28
2.4 Universal Functions for arrays . . . . . . . . . . . . . . . . . . . . . . 30
2.5 Summary of new features . . . . . . . . . . . . . . . . . . . . . . . . 3 2
2.6 Summary of differences with Numeric . . . . . . . . . . . . . . . . . 34
2.6.1 First-step changes . . . . . . . . . . . . . . . . . . . . . . . . 34
2.6.2 Second-step changes . . . . . . . . . . . . . . . . . . . . . . . 37
2.6.3 Updating code tha t uses Numeric using alter codeN . . . . . 38
2.6.4 Changes to think about . . . . . . . . . . . . . . . . . . . . . 39
2.7 Summary of differences with Numarray . . . . . . . . . . . . . . . . 40
2.7.1 First-step changes . . . . . . . . . . . . . . . . . . . . . . . . 41
2.7.1.1 Import changes . . . . . . . . . . . . . . . . . . . . . 41
2.7.1.2 Attribute and method changes . . . . . . . . . . . . 42
2.7.2 Second-step changes . . . . . . . . . . . . . . . . . . . . . . . 43
2.7.3 Additional Extension modules . . . . . . . . . . . . . . . . . . 43
3 The Array Object 45
3.1 ndarray Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.1.1 Memory Layout a ttributes . . . . . . . . . . . . . . . . . . . . 46
3.1.2 Data Type attributes . . . . . . . . . . . . . . . . . . . . . . 50
2

3.1.3 Other attributes . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.1.4 Array Interface attributes . . . . . . . . . . . . . . . . . . . . 52
3.2 ndarray Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.2.1 Array conversion . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.2.2 Array shape manipulation . . . . . . . . . . . . . . . . . . . . 60
3.2.3 Array item selectio n and ma nipulatio n . . . . . . . . . . . . . 62
3.2.4 Array calculation . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.3 Array Special Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.3.1 Methods for standa rd library functions . . . . . . . . . . . . . 72
3.3.2 Basic customization . . . . . . . . . . . . . . . . . . . . . . . 73
3.3.3 Container customization . . . . . . . . . . . . . . . . . . . . . 75
3.3.4 Arithmetic customization . . . . . . . . . . . . . . . . . . . . 76
3.3.4.1 Binary . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.3.4.2 In-place . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.3.4.3 Unary operations . . . . . . . . . . . . . . . . . . . 79
3.4 Array indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.1 Basic Slicing . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.4.2 Advanced selection . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4.2.1 Integer . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.4.2.2 Boolean . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.4.3 Flat Iterator indexing . . . . . . . . . . . . . . . . . . . . . . 85
4 Basic Routines 86
4.1 Creating arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.2 Operations on two or more arrays . . . . . . . . . . . . . . . . . . . . 91
4.3 Printing a rrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.4 Functions r e dundant with methods . . . . . . . . . . . . . . . . . . 95
4.5 Dealing with data types . . . . . . . . . . . . . . . . . . . . . . . . . 96
5 Additional Convenience Routine s 98
5.1 Shap e functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
5.2 Basic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
5.3 Polynomial functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.4 Set Oper ations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
5.5 Array constr uctio n using index tricks . . . . . . . . . . . . . . . . . . 114
5.6 Other indexing devices . . . . . . . . . . . . . . . . . . . . . . . . . . 117
5.7 Two-dimensional functions . . . . . . . . . . . . . . . . . . . . . . . . 118
3

5.8 More data typ e functions . . . . . . . . . . . . . . . . . . . . . . . . 12 0
5.9 Functions that behave like ufuncs . . . . . . . . . . . . . . . . . . . . 123
5.10 Miscella neous Functions . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.11 Utility functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
6 Scalar objects 128
6.1 Attributes of array sca lars . . . . . . . . . . . . . . . . . . . . . . . . 129
6.2 Methods of array scalars . . . . . . . . . . . . . . . . . . . . . . . . . 131
6.3 Defining New Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
7 Data-type (dtype) Objects 133
7.1 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
7.2 Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
7.3 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
8 Standard Classes 141
8.1 Special attributes a nd methods recognized by NumPy . . . . . . . . 142
8.2 Matrix Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
8.3 Memory-mapped-file arrays . . . . . . . . . . . . . . . . . . . . . . . 145
8.4 Character arrays (numpy.char) . . . . . . . . . . . . . . . . . . . . . 146
8.5 Record Arrays (numpy.rec) . . . . . . . . . . . . . . . . . . . . . . . 147
8.6 Masked Arrays (numpy.ma) . . . . . . . . . . . . . . . . . . . . . . . 151
8.7 Standard container class . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.8 Array Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.8.1 Default iteration . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.8.2 Flat iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
8.8.3 N-dimensional enumeration . . . . . . . . . . . . . . . . . . . 154
8.8.4 Iterator for broadcasting . . . . . . . . . . . . . . . . . . . . . 154
9 Universal Functions 156
9.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 6
9.1.1 Broadcasting . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
9.1.2 Output type deter mina tion . . . . . . . . . . . . . . . . . . . 157
9.1.3 Use of internal buffers . . . . . . . . . . . . . . . . . . . . . . 158
9.1.4 Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . 158
9.1.5 Optional keyword arguments . . . . . . . . . . . . . . . . . . 159
9.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.3 Casting Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
4

9.4 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.4.1 Reduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.4.2 Accumulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.4.3 Reduceat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
9.4.4 Outer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
9.5 Available ufuncs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
9.5.1 Math operatio ns . . . . . . . . . . . . . . . . . . . . . . . . . 167
9.5.2 Trigonometric functions . . . . . . . . . . . . . . . . . . . . . 170
9.5.3 Bit-twiddling functions . . . . . . . . . . . . . . . . . . . . . . 171
9.5.4 Comparison functions . . . . . . . . . . . . . . . . . . . . . . 172
9.5.5 Floating functions . . . . . . . . . . . . . . . . . . . . . . . . 174
10 Basic Modules 177
10.1 Linear Algebra (linalg) . . . . . . . . . . . . . . . . . . . . . . . . 1 77
10.2 Discrete Fourier Transforms (fft) . . . . . . . . . . . . . . . . . . . 180
10.3 Rando m Numbers (random) . . . . . . . . . . . . . . . . . . . . . . 184
10.3.1 Discrete Distributions . . . . . . . . . . . . . . . . . . . . . . 185
10.3.2 C ontinuous Distributions . . . . . . . . . . . . . . . . . . . . 187
10.3.3 Mis c ellaneous utilities . . . . . . . . . . . . . . . . . . . . . . 194
10.4 Matrix-specific functions (matlib) . . . . . . . . . . . . . . . . . . . . 194
10.5 Ctypes utiltity functions (ctypeslib) . . . . . . . . . . . . . . . . . . 194
11 Testing and Packaging 196
11.1 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
11.2 NumPy Distutils . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
11.2.1 misc util . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
11.2.2 Other modules . . . . . . . . . . . . . . . . . . . . . . . . . . 206
11.3 Conversion of .src files . . . . . . . . . . . . . . . . . . . . . . . . . . 208
11.3.1 Fortran files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
11.3.1.1 Named r e peat rule . . . . . . . . . . . . . . . . . . . 208
11.3.1.2 Short repeat rule . . . . . . . . . . . . . . . . . . . . 208
11.3.1.3 Pre-defined na mes . . . . . . . . . . . . . . . . . . . 209
11.3.2 Other files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
II C-API 211
12 New Python Types and C-Structures 212
5
剩余377页未读,继续阅读




















Howardk
- 粉丝: 173
- 资源: 16
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- Xilinx SRIO详解.pptx
- Informatica PowerCenter 10.2 for Centos7.6安装配置说明.pdf
- 现代无线系统射频电路实用设计卷II 英文版.pdf
- 电子产品可靠性设计 自己讲课用的PPT,包括设计方案的可靠性选择,元器件的选择与使用,降额设计,热设计,余度设计,参数优化设计 和 失效分析等
- MPC5744P-DEV-KIT-REVE-QSG.pdf
- 通信原理课程设计报告(ASK FSK PSK Matlab仿真--数字调制技术的仿真实现及性能研究)
- ORIGIN7.0使用说明
- 在VMware Player 3.1.3下安装Redhat Linux详尽步骤
- python学生信息管理系统实现代码
- 西门子MES手册 13 OpcenterEXCR_PortalStudio1_81RB1.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0