说明
uniform()
随机生成平均分布的数据。
normal()
随机生成正太分布的数据。
randint()
随机生成平均分布的整数的数据
rand()
随机生成0,1平均分布的数据
randn()
随机生成标准正太分布的数据
shuffle()
随机打乱数组
代码
# numpy.random 的简单使用
from numpy import random as rd
import numpy as np
# 产生 2 * 2 的 服从 [1,10) 均匀分布的矩阵
res1 = rd.uniform(low=1, high=10, size=(2,2))
# 产生 2 * 2 的 服从 均值为0 方差为1 的正太分布的矩阵
res2 = rd.normal(loc=0, scale=1.0, size=(2,2))
# 产生 2 * 2 的 服从 [1,10) 均匀分布的矩阵 ,但是取值都是整数
res3 = rd.randint(low=1, high=10, size=(2,2))
res4 = rd.rand(2, 2) # 等价于 uniform 中 low = 0 high = 1
res5 = rd.randn(2, 2) # 等价于 normal 中 loc=0, scale=1.0
#原地随机打乱数组 shuffle: 洗牌
x = np.arange(10)
rd.shuffle(x) # return None
print(x)