How to random sample a 2-parameter weibull distribution in python

后端 未结 2 1888
抹茶落季
抹茶落季 2021-01-19 20:54

I was wondering how to generate a random weibull distribution with 2-parameter (lambda, k) in python. I know that numpy has a numpy.random.weibull, but it only accepts the <

2条回答
  •  一生所求
    2021-01-19 21:14

    Severin Pappadeux's answer is probably the simplest way to include the scale parameter. An alternative is to use scipy.stats.weibull_min. weibull_min has three parameters: shape, location and scale. You only want the shape and scale, so you would set the location to 0.

    from scipy.stats import weibull_min
    
    n = 100     # number of samples
    k = 2.4     # shape
    lam = 5.5   # scale
    
    x = weibull_min.rvs(k, loc=0, scale=lam, size=n)
    

提交回复
热议问题