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])
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短