Repository navigation
Expand file tree
/
Copy pathmodule_3.html
More file actions
334 lines (217 loc) · 19.6 KB
/
Copy pathmodule_3.html
File metadata and controls
334 lines (217 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh-CN" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh-CN" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>模组3:NumPy基础 — Python Like You Mean It</title>
<script type="text/javascript" src="_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/language_data.js"></script>
<script src="https://www.googletagmanager.com/gtag/js?id=UA-115029372-1"></script>
<script src="_static/gtag.js"></script>
<script src="_static/translations.js"></script>
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/my_theme.css" type="text/css" />
<link rel="index" title="索引" href="genindex.html" />
<link rel="search" title="搜索" href="search.html" />
<link rel="next" title="N维数组简介" href="Module3_IntroducingNumpy/IntroducingTheNDarray.html" />
<link rel="prev" title="编码为字符串" href="Module2_EssentialsOfPython/Problems/EncodeAsString.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home"> Python Like You Mean It
</a>
<div class="version">
1.4
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">目录:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="intro.html">Python Like You Mean It</a></li>
<li class="toctree-l1"><a class="reference internal" href="module_1.html">模组1:Python入门</a></li>
<li class="toctree-l1"><a class="reference internal" href="module_2.html">模组2:Python基础</a></li>
<li class="toctree-l1"><a class="reference internal" href="module_2_problems.html">模组2:题目</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">模组3:NumPy基础</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/IntroducingTheNDarray.html">N维数组简介</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html">访问数组多维度的内容</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicArrayAttributes.html">基本的数组属性</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html">创建NumPy数组的函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/ArrayTraversal.html">迭代数组和数组遍历顺序</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html">“矢量化”操作:对NumPy数组进行优化过的计算</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html">数组广播</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html">基础和进阶索引简介</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html">进阶索引</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="module_3_problems.html">模组3:题目</a></li>
<li class="toctree-l1"><a class="reference internal" href="module_4.html">模组4:面向对象编程</a></li>
<li class="toctree-l1"><a class="reference internal" href="module_5.html">模组5:琐碎话题</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">Python Like You Mean It</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>模组3:NumPy基础</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/module_3.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<style>
/* CSS overrides for sphinx_rtd_theme */
/* 24px margin */
.nbinput.nblast.container,
.nboutput.nblast.container {
margin-bottom: 19px; /* padding has already 5px */
}
/* ... except between code cells! */
.nblast.container + .nbinput.container {
margin-top: -19px;
}
.admonition > p:before {
margin-right: 4px; /* make room for the exclamation icon */
}
/* Fix math alignment, see https://github.com/rtfd/sphinx_rtd_theme/pull/686 */
.math {
text-align: unset;
}
</style>
<div class="section" id="numpy">
<h1>模组3:NumPy基础<a class="headerlink" href="#numpy" title="永久链接至标题">¶</a></h1>
<p>NumPy就是Python能和R,Matlab,和Julia这一级别的语言在进行科学有关的数据处理工作相提并论的原因。它作为一个第三方模组(也就是说它不是Python标准库的一部分)为用户提供了一个多功能的数组对象和强大的操作这些数组的数学函数;这些都用来帮助用户使用Python进行数字工作。NumPy通过矢量化(vectorization)这一过程来高度优化它很多的功能并取得Python语言正常情况下无法达到的计算效率。</p>
<p>NumPy对Python数据处理界的影响毋庸置疑。不管你是在matplotlib中绘制数据,通过 <a class="reference external" href="https://pandas.pydata.org">pandas</a> 和 <a class="reference external" href="https://xarray.pydata.org/en/stable">xarray</a> 分析数据,使用 <a class="reference external" href="https://opencv.org">OpenCV</a> 处理图片和视屏,用 <a class="reference external" href="www.astropy.org">astropy</a> 进行天文学研究,或是通过 <a class="reference external" href="https://scikit-learn.org/stable/index.html">Scikit-Learn</a> 和 <a class="reference external" href="https://mygrad.readthedocs.io">MyGrad</a> 来尝试机器学习,你走在使用受到NumPy深远影响的Python模组。在它们的最核心,这些模组都依赖着NumPy的N维数组和它高效的矢量化功能。NumPy也从根本性上影响了这些模组的设计以及它们对用户开放的接口。因此,熟练使用这些工具并进行Python科学工作都建立在对NumPy扎实的理解上。</p>
<p>本模组向我们介绍NumPy的基础。我们将首先定义维度(dimensionality)一词的具体含义并发展对零,一,二,和N维数组以及它们为什么对数据科学应用如此重要的直观理解。然后,我们将会讨论数组遍历顺序的不明确点以及NumPy默认使用的行优先排序。然后我们将会讨论极其重要的矢量化,其描述了NumPy向发送对数组进行的数学操作的方法。这也将帮助我们理解NumPy如何得到它如此高的计算效率。最后,我们将会深入讨论NumPy的高级功能。这包括它为不同形状的数组之间的数学操作进行广播(broadcast)的规则,以及通过基础和进阶索引来访问和更新数组的内容的方法。有了这些技巧折后,我们将能够使用NumPy和Python很多其它的科学模组来编写短小精悍的数组处理代码!</p>
<div class="toctree-wrapper compound">
<p class="caption"><span class="caption-text">内容:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/IntroducingTheNDarray.html">N维数组简介</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/IntroducingTheNDarray.html#官方说明文档链接">官方说明文档链接</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html">访问数组多维度的内容</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#一维数组">一维数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#二维数组">二维数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#N维数组">N维数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#零维数组">零维数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#操作数组">操作数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#官方说明文档链接">官方说明文档链接</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AccessingDataAlongMultipleDimensions.html#阅读理解答案:">阅读理解答案:</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/BasicArrayAttributes.html">基本的数组属性</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicArrayAttributes.html#官方说明文档链接">官方说明文档链接</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html">创建NumPy数组的函数</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#使用Python序列创建数组">使用Python序列创建数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#创建常量数组:zeros-和-ones">创建常量数组:<code class="docutils literal notranslate"><span class="pre">zeros</span></code> 和 <code class="docutils literal notranslate"><span class="pre">ones</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#创建序列数组:arange-和-linspace">创建序列数组:<code class="docutils literal notranslate"><span class="pre">arange</span></code> 和 <code class="docutils literal notranslate"><span class="pre">linspace</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#随机取值来生成数组">随机取值来生成数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#创建某数据类型的数组">创建某数据类型的数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#合并数组">合并数组</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/FunctionsForCreatingNumpyArrays.html#官方说明文档链接">官方说明文档链接</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/ArrayTraversal.html">迭代数组和数组遍历顺序</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/ArrayTraversal.html#如何遍历数组:行优先(C)vs-列优先(F)遍历顺序">如何遍历数组:行优先(C)vs 列优先(F)遍历顺序</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/ArrayTraversal.html#官方说明文档链接">官方说明文档链接</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html">“矢量化”操作:对NumPy数组进行优化过的计算</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#使用数组进行基本数学操作">使用数组进行基本数学操作</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#矢量化操作">矢量化操作</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#NumPy的数学函数">NumPy的数学函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#逻辑运算">逻辑运算</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#线性代数">线性代数</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#总结">总结</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#官方说明文档链接">官方说明文档链接</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/VectorizedOperations.html#阅读理解答案:">阅读理解答案:</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html">数组广播</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html#广播的规则">广播的规则</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html#数组广播的简单应用">数组广播的简单应用</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html#大小为1的轴和-newaxis-对象">大小为1的轴和 <code class="docutils literal notranslate"><span class="pre">newaxis</span></code> 对象</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html#广播的高级运用:距离对">广播的高级运用:距离对</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html#官方说明文档链接">官方说明文档链接</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/Broadcasting.html#阅读理解答案">阅读理解答案</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html">基础和进阶索引简介</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html#基础索引">基础索引</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html#创建数组视阈">创建数组视阈</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html#增强数组的内置数据">增强数组的内置数据</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html#官方说明文档链接">官方说明文档链接</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/BasicIndexing.html#阅读理解答案:">阅读理解答案:</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html">进阶索引</a><ul>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html#整数数组索引">整数数组索引</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html#布尔数组索引">布尔数组索引</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html#通过进阶索引进行原地和增强赋值">通过进阶索引进行原地和增强赋值</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html#混合使用基础和进阶索引">混合使用基础和进阶索引</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html#官方说明文档链接">官方说明文档链接</a></li>
<li class="toctree-l2"><a class="reference internal" href="Module3_IntroducingNumpy/AdvancedIndexing.html#阅读理解答案:">阅读理解答案:</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="Module3_IntroducingNumpy/IntroducingTheNDarray.html" class="btn btn-neutral float-right" title="N维数组简介" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="Module2_EssentialsOfPython/Problems/EncodeAsString.html" class="btn btn-neutral float-left" title="编码为字符串" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2019, Ryan Soklaski
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>