NumPy
NumPy是Python进行科学计算的基础模块/包/库。它包含以下部分:
- 强大的多维(N-dimensional) 数组/矩阵对象
- 复杂的(广播) 函数
- 整合 C/C++ 和 Fortran 代码的工具
- 实用的线性代数、傅里叶变换、随机数
除了它广为人知的科学计算应用, NumPy 还可以作为泛型数据高效的多维容器. 可以定义任意的数据类型使得NumPy能够无缝高效的整合各种数据库。
要学习numpy我们要了解Python的几种内建容器类型
lists, dictionaries, sets, and tuples
列表、字典、集合、元组
minasah开始学习numpy了额
We can initialize numpy arrays from nested Python lists, and access elements using square brackets:
我们可以通过嵌套的python列表来初始一个numpy数组,通过一般数组的下表结合中括号来进行元素访问:
import numpy as np
#一般导入numpy模块的格式如上
初识
>>> import numpy as np
>>> a = np.arange(15).reshape(3, 5)
#np.arange( 0, 2, 0.3 )也接受浮点参数
array([ 0. , 0.3, 0.6, 0.9, 1.2, 1.5, 1.8])
#产生15个数组元素,然后分为三行五列
>>> a
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
>>> a.shape
(3, 5)
>>> a.ndim
2
>>> a.dtype.name
'int64'
>>> a.itemsize
8
>>> a.size
15
>>> type(a)
<type 'numpy.ndarray'>
>>> b = np.array([6, 7, 8])
>>> b
array([6,