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 生日广州男生祝福语简短