Skip to content

Commit bc81d60

Browse files
committed
(翻译文档)快速入门教程
1 parent a96bf8f commit bc81d60

File tree

8 files changed

+650
-1104
lines changed

8 files changed

+650
-1104
lines changed

docs/.vuepress/sidebar/user_zh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = function () {
2424
['/user/basics/', '目录'],
2525
['/user/basics/types', '数据类型'],
2626
['/user/basics/creation', '创建数组'],
27-
['/user/basics/io', '输入输出'],
27+
['/user/basics/io', 'NumPy与输入输出'],
2828
['/user/basics/indexing', '索引'],
2929
['/user/basics/broadcasting', '广播'],
3030
['/user/basics/byteswapping', '字节交换'],

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ meta:
77
content: 这是NumPy官方的中文文档,NumPy是用Python进行科学计算的基础软件包。
88
heroImage: /logo.svg
99
actionText: 快速开始 →
10-
actionLink: /docs/
10+
actionLink: /user/
1111
footer: 署名-非商业性使用-相同方式共享 3.0 中国大陆 (CC BY-NC-SA 3.0 CN) | Copyright © 2019-present Zhi Bing
1212
---
1313

docs/user/basics/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# NumPy basics
1+
# NumPy 基础知识
22

3-
- [Data types](/user/basics/types.html)
4-
- [Array creation](/user/basics/creation.html)
5-
- [I/O with NumPy](/user/basics/io.html)
6-
- [Indexing](/user/basics/indexing.html)
7-
- [Broadcasting](/user/basics/broadcasting.html)
8-
- [Byte-swapping](/user/basics/byteswapping.html)
9-
- [Structured arrays](/user/basics/rec.html)
10-
- [Writing custom array containers](/user/basics/dispatch.html)
11-
- [Subclassing ndarray](/user/basics/subclassing.html)
3+
- [数据类型](/user/basics/types.html)
4+
- [创建数组](/user/basics/creation.html)
5+
- [NumPy与输入输出](/user/basics/io.html)
6+
- [索引](/user/basics/indexing.html)
7+
- [广播](/user/basics/broadcasting.html)
8+
- [字节交换](/user/basics/byteswapping.html)
9+
- [结构化数组](/user/basics/rec.html)
10+
- [编写自定义数组容器](/user/basics/dispatch.html)
11+
- [子类化数组](/user/basics/subclassing.html)

docs/user/basics/creation.md

Lines changed: 44 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,105 @@
1-
# Array creation
1+
# 创建数组
22

3-
::: tip See also
3+
::: tip 另见
44

5-
[Array creation routines](https://numpy.org/devdocs/reference/routines.array-creation.html#routines-array-creation)
5+
[数组创建相关API](/reference/routines.array-creation.html#routines-array-creation)
66

77
:::
88

9-
## Introduction
9+
## 简介
1010

11-
There are 5 general mechanisms for creating arrays:
11+
创建数组有5种常规机制:
1212

13-
1. Conversion from other Python structures (e.g., lists, tuples)
14-
1. Intrinsic numpy array creation objects (e.g., arange, ones, zeros,
15-
etc.)
16-
1. Reading arrays from disk, either from standard or custom formats
17-
1. Creating arrays from raw bytes through the use of strings or buffers
18-
1. Use of special library functions (e.g., random)
13+
1. 从其他Python结构(例如,列表,元组)转换
14+
1. numpy原生数组的创建(例如,arange、ones、zeros等)
15+
1. 从磁盘读取数组,无论是标准格式还是自定义格式
16+
1. 通过使用字符串或缓冲区从原始字节创建数组
17+
1. 使用特殊库函数(例如,random)
1918

20-
This section will not cover means of replicating, joining, or otherwise
21-
expanding or mutating existing arrays. Nor will it cover creating object
22-
arrays or structured arrays. Both of those are covered in their own sections.
19+
本节不包括复制,连接或以其他方式扩展或改变现有数组的方法。它也不会涵盖创建对象数组或结构化数组。这些都包含在他们自己的章节中。
2320

24-
## Converting Python array_like Objects to NumPy Arrays
21+
## 将Python array_like对象转换为Numpy数组
2522

26-
In general, numerical data arranged in an array-like structure in Python can
27-
be converted to arrays through the use of the array() function. The most
28-
obvious examples are lists and tuples. See the documentation for array() for
29-
details for its use. Some objects may support the array-protocol and allow
30-
conversion to arrays this way. A simple way to find out if the object can be
31-
converted to a numpy array using array() is simply to try it interactively and
32-
see if it works! (The Python Way).
23+
通常,在Python中排列成array-like结构的数值数据可以通过使用array()函数转换为数组。最明显的例子是列表和元组。有关其使用的详细信息,请参阅array()的文档。一些对象可能支持数组协议并允许以这种方式转换为数组。找出对象是否可以使用array()转换为一个数组numpy 数组的简单方法很简单,只要交互式试一下,看看它是否工作!(Python方式)。
3324

34-
Examples:
25+
例子:
3526

36-
``` python
27+
```python
3728
>>> x = np.array([2,3,1,0])
3829
>>> x = np.array([2, 3, 1, 0])
3930
>>> x = np.array([[1,2.0],[0,0],(1+1j,3.)]) # note mix of tuple and lists,
4031
and types
4132
>>> x = np.array([[ 1.+0.j, 2.+0.j], [ 0.+0.j, 0.+0.j], [ 1.+1.j, 3.+0.j]])
4233
```
4334

44-
## Intrinsic NumPy Array Creation
35+
## Numpy原生数组的创建
4536

46-
NumPy has built-in functions for creating arrays from scratch:
37+
Numpy内置了从头开始创建数组的函数:
4738

48-
zeros(shape) will create an array filled with 0 values with the specified
49-
shape. The default dtype is float64.
39+
zeros(shape)将创建一个用指定形状用0填充的数组。默认的dtype是float64。
5040

51-
``` python
52-
>>> np.zeros((2, 3))
53-
array([[ 0., 0., 0.], [ 0., 0., 0.]])
41+
```python
42+
>>> np.zeros((2, 3)) array([[ 0., 0., 0.], [ 0., 0., 0.]])
5443
```
5544

56-
ones(shape) will create an array filled with 1 values. It is identical to
57-
zeros in all other respects.
45+
ones(shape)将创建一个用1个值填充的数组。它在所有其他方面与zeros相同。
5846

59-
arange() will create arrays with regularly incrementing values. Check the
60-
docstring for complete information on the various ways it can be used. A few
61-
examples will be given here:
47+
arange()将创建具有有规律递增值的数组。检查文档字符串以获取有关可以使用的各种方式的完整信息。这里给出几个例子:
6248

63-
``` python
49+
```python
6450
>>> np.arange(10)
6551
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
66-
>>> np.arange(2, 10, dtype=float)
52+
>>> np.arange(2, 10, dtype=np.float)
6753
array([ 2., 3., 4., 5., 6., 7., 8., 9.])
6854
>>> np.arange(2, 3, 0.1)
6955
array([ 2. , 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9])
7056
```
7157

72-
Note that there are some subtleties regarding the last usage that the user
73-
should be aware of that are described in the arange docstring.
58+
请注意,关于用户应该注意的最后用法在arange文档字符串中有一些细微的描述。
7459

75-
linspace() will create arrays with a specified number of elements, and
76-
spaced equally between the specified beginning and end values. For
77-
example:
60+
linspace() 将创建具有指定数量元素的数组,并在指定的开始值和结束值之间平均间隔。例如:
7861

79-
``` python
62+
```python
8063
>>> np.linspace(1., 4., 6)
8164
array([ 1. , 1.6, 2.2, 2.8, 3.4, 4. ])
8265
```
8366

84-
The advantage of this creation function is that one can guarantee the
85-
number of elements and the starting and end point, which arange()
86-
generally will not do for arbitrary start, stop, and step values.
67+
这个创建函数的优点是可以保证元素的数量以及开始和结束点,对于任意的开始,停止和步骤值,arange()通常不会这样做。
8768

88-
indices() will create a set of arrays (stacked as a one-higher dimensioned
89-
array), one per dimension with each representing variation in that dimension.
90-
An example illustrates much better than a verbal description:
69+
indices() 将创建一组数组(堆积为一个更高维的数组),每个维度一个,每个维度表示该维度中的变化。一个例子说明比口头描述要好得多:
9170

92-
``` python
71+
```python
9372
>>> np.indices((3,3))
9473
array([[[0, 0, 0], [1, 1, 1], [2, 2, 2]], [[0, 1, 2], [0, 1, 2], [0, 1, 2]]])
9574
```
9675

97-
This is particularly useful for evaluating functions of multiple dimensions on
98-
a regular grid.
76+
这对于评估常规网格上多个维度的功能特别有用。
9977

100-
## Reading Arrays From Disk
78+
## 从磁盘读取数组
10179

102-
This is presumably the most common case of large array creation. The details,
103-
of course, depend greatly on the format of data on disk and so this section
104-
can only give general pointers on how to handle various formats.
80+
这大概是大阵列创建的最常见情况。当然,细节很大程度上取决于磁盘上的数据格式,所以本节只能给出如何处理各种格式的一般指示。
10581

106-
### Standard Binary Formats
82+
### 标准二进制格式
10783

108-
Various fields have standard formats for array data. The following lists the
109-
ones with known python libraries to read them and return numpy arrays (there
110-
may be others for which it is possible to read and convert to numpy arrays so
111-
check the last section as well)
84+
各种字段都有阵列数据的标准格式。下面列出了那些已知的Python库来读取它们并返回numpy数组(可能有其他可能读取并转换为numpy数组的其他数据,因此请检查最后一节)
11285

113-
``` python
86+
```
11487
HDF5: h5py
11588
FITS: Astropy
11689
```
11790

118-
Examples of formats that cannot be read directly but for which it is not hard to
119-
convert are those formats supported by libraries like PIL (able to read and
120-
write many image formats such as jpg, png, etc).
91+
无法直接读取但不易转换的格式示例是像PIL这样的库支持的格式(能够读取和写入许多图像格式,如jpg,png等)。
12192

122-
### Common ASCII Formats
93+
### 常见ASCII格式
12394

124-
Comma Separated Value files (CSV) are widely used (and an export and import
125-
option for programs like Excel). There are a number of ways of reading these
126-
files in Python. There are CSV functions in Python and functions in pylab
127-
(part of matplotlib).
95+
逗号分隔值文件(CSV)被广泛使用(以及Excel等程序的导出和导入选项)。有很多方法可以在Python中阅读这些文件。python中有CSV函数和pylab函数(matplotlib的一部分)。
12896

129-
More generic ascii files can be read using the io package in scipy.
97+
更多通用的ascii文件可以在scipy中使用io软件包读取。
13098

131-
### Custom Binary Formats
99+
### 自定义二进制格式
132100

133-
There are a variety of approaches one can use. If the file has a relatively
134-
simple format then one can write a simple I/O library and use the numpy
135-
fromfile() function and .tofile() method to read and write numpy arrays
136-
directly (mind your byteorder though!) If a good C or C++ library exists that
137-
read the data, one can wrap that library with a variety of techniques though
138-
that certainly is much more work and requires significantly more advanced
139-
knowledge to interface with C or C++.
101+
有各种各样的方法可以使用。如果文件具有相对简单的格式,那么可以编写一个简单的 I/O 库,并使用 numpy fromfile() 函数和 .tofile() 方法直接读取和写入numpy数组(尽管介意你的字节序)!如果存在一个读取数据的良好 C 或 C++ 库,可以使用各种技术来封装该库,但这肯定要做得更多,并且需要更多的高级知识才能与C或C++ 接口。
140102

141-
### Use of Special Libraries
103+
### 使用特殊库
142104

143-
There are libraries that can be used to generate arrays for special purposes
144-
and it isn’t possible to enumerate all of them. The most common uses are use
145-
of the many array generation functions in random that can generate arrays of
146-
random values, and some utility functions to generate special matrices (e.g.
147-
diagonal).
105+
有些库可用于生成特殊用途的数组,且无法列出所有的这些库。最常见的用途是随机使用许多数组生成函数,这些函数可以生成随机值数组,以及一些实用函数来生成特殊矩阵(例如对角线)。

0 commit comments

Comments
 (0)