- 熟悉基础常量、常见数据类型,以及时间日期和时间增量的处理。
- 掌握数组的创建和数组的属性。
常量
numpy.nan
numpy.inf
numpy.pi
numpy.e
数据类型
类型 | 备注 | 说明 |
---|---|---|
bool_ = bool8 | 8位 | 布尔类型 |
int8 = byte | 8位 | 整型 |
int16 = short | 16位 | 整型 |
int32 = intc | 32位 | 整型 |
int_ = int64 = long = int0 = intp | 64位 | 整型 |
uint8 = ubyte | 8位 | 无符号整型 |
uint16 = ushort | 16位 | 无符号整型 |
uint32 = uintc | 32位 | 无符号整型 |
uint64 = uintp = uint0 = uint | 64位 | 无符号整型 |
float16 = half | 16位 | 浮点型 |
float32 = single | 32位 | 浮点型 |
float_ = float64 = double | 64位 | 浮点型 |
str = unicode = str0 = unicode | Unicode 字符串 | |
datetime64 | 日期时间类型 | |
timedelta64 | 表示两个时间之间的间隔 |
字符 | 对应类型 | 备注 |
---|---|---|
b | boolean | 'b1' |
i | signed integer | 'i1', 'i2', 'i4', 'i8' |
u | unsigned integer | 'u1', 'u2' ,'u4' ,'u8' |
f | floating-point | 'f2', 'f4', 'f8' |
c | complex floating-point | |
m | timedelta64 | 表示两个时间之间的间隔 |
M | datetime64 | 日期时间类型 |
O | object | |
S | (byte-)string | S3表示长度为3的字符串 |
U | Unicode | Unicode 字符串 |
V | void |
时间日期和时间增量
datetime64 基础
日期单位 | 代码含义 | 时间单位 | 代码含义 |
---|---|---|---|
Y | 年 | h | 小时 |
M | 月 | m | 分钟 |
W | 周 | s | 秒 |
D | 天 | ms | 毫秒 |
- | - | us | 微秒 |
- | - | ns | 纳秒 |
- | - | ps | 皮秒 |
- | - | fs | 飞秒 |
- | - | as | 阿托秒 |
数组的创建
数组的创建
numpy 提供的最重要的数据结构是ndarray,它是 python 中list的扩展。
1. 依据现有数据来创建 ndarray
(a)通过array()函数进行创建。
(b)通过asarray()函数进行创建
(c)通过fromfunction()函数进行创建
2. 依据 ones 和 zeros 填充方式
(a)零数组
(b)1数组
(c)空数组
(d)单位数组
(e)对角数组
(f)常数数组
3. 利用数值范围来创建ndarray
4. 结构数组的创建
(a)利用字典来定义结构
(b)利用包含多个元组的列表来定义结构