import numpy as np
print(np.random.random()) # 0.9712291171155641
print(np.random.random(3)) # [0.54426685 0.10859501 0.66425772]
print(np.random.choice([2, 3, 5, 7], 5)) # [7 7 3 5 3]
print(np.random.randint(2, 10)) # 7
print(np.random.randint(2, 10, 3)) # [5 3 5]
print(np.random.randint(2, 10, (2, 2))) # [[2 7]
# [3 2]]
np.random.normal(loc=μ,scale=δ,size=shape)正态分布
mdt = np.random.normal(0, 1, 100) # 产生服从标准正态分布的100个随机数
# Numpy Functions: min() max() mean() median() std()(标准差)
print(f'min: {mdt.min(): .2f}, max: {mdt.max(): .2f}, mean: {mdt.mean(): .2f}, std: {mdt.std(): .2f}')
# min: -2.67, max: 2.88, mean: -0.01, std: 1.02
# (repeating sequences) np.tile np.repeat
print(np.tile([1, 3, 2], 2)) # [1 3 2 1 3 2]
print(np.repeat([1, 3, 2], 2)) # [1 1 3 3 2 2]
import matplotlib.pyplot as plt
plt.hist(mdt, color="grey", bins=21)
plt.show()
![标准正态分布(100个随机数)](https://img-blog.csdnimg.cn/3dfc1db9560d4d04958e02b83b48b588.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA6IuP6Zuo5rWB5Liw,size_20,color_FFFFFF,t_70,g_se,x_16)