| random.random |
生成0~1之间的随机数 |
| random.uniform |
生成均匀分布的随机数 |
| random.randn |
生成标准正态的随机数 |
| random.randint |
生成随机的整数 |
| random.normal |
生成正态分布 |
| random.shuffle |
随机打乱顺序 |
| random.seed |
设置随机种子 |
| random_sample |
生成随机的浮点数 |
| ### 3. 创建特定形状的多维数组 |
|
| 函数 |
描述 |
| -------------------- |
----------------------------- |
| np.zeros((3,4)) |
创建3x4全为0的数组 |
| np.ones((3,4)) |
创建3x4全为1的数组 |
| np.empty((3,4)) |
创建空数组(非0) |
| np.zeros_like(ndarr) |
创建相同维度的0数组 |
| np.ones_like(ndarr) |
同上 |
| np.empty_like(ndarr) |
同上 |
| np.eye(5) |
创建5x5矩阵(对角为1,其他为0 |
| np.full((3,4),666) |
创建全为666的3x4数组 |
| ### 4. 利用arange、linspace函数生成数组 |
|
1. arange([start,] stop[, step,], dtype = None) |
|
1. start指定起始:默认0 |
|
2. stop指定终末:不可少 |
|
3. step指定步长:默认1 |
|
2. linspace(start, stop, num = 50, endpoint = True, retstep = False, dtype = None) |
|
| - 根据输入的指定数据范围以及等份数量,自动生成一个线性等分向量 |
|
import numpy as np
print(np.linspace(0, 1, 10))
|
|
| ## 获取元素 |
|
 |
|
1. [:,:-1]: This will take all rows and all but the last column. |
|
2. [:,-1]: This will take all rows and only the last column. |
|
3. :denotes "all", and -1 in indexing means the last row/column. |
|