numpy 从特定分布生成随机数
示例
从正态(高斯)分布中抽取样本
# Generate 5 random numbers from a standard normal distribution # (mean = 0, standard deviation = 1) np.random.randn(5) # Out: array([-0.84423086, 0.70564081, -0.39878617, -0.82719653, -0.4157447 ]) # This result can also be achieved with the more general np.random.normal np.random.normal(0, 1, 5) # Out: array([-0.84423086, 0.70564081, -0.39878617, -0.82719653, -0.4157447 ]) # Specify the distribution's parameters # Generate 5 random numbers drawn from a normal distribution with mean=70, std=10 np.random.normal(70, 10, 5) # Out: array([ 72.06498837, 65.43118674, 59.40024236, 76.14957316, 84.29660766])
有可用几个额外的分布numpy.random,例如poisson,binomial和logistic
np.random.poisson(2.5, 5) # 5 numbers, lambda=5 # Out: array([0, 2, 4, 3, 5]) np.random.binomial(4, 0.3, 5) # 5 numbers, n=4, p=0.3 # Out: array([1, 0, 2, 1, 0]) np.random.logistic(2.3, 1.2, 5) # 5 numbers, location=2.3, scale=1.2 # Out: array([ 1.23471936, 2.28598718, -0.81045893, 2.2474899 , 4.15836878])
热门推荐
3 庆双节祝福语简短
4 圆圆的祝福语简短
10 很暧昧的简短祝福语
11 简短祝福语大全暖心
12 年末祝福语简短的文案
13 婆婆生日祝福语简短的
14 简短的祝福语12字
15 别人生辰祝福语简短
16 跨年的生日祝福语简短
17 足球队祝福语简短
18 元旦联谊祝福语简短精辟