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

2

8

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 a parameter as the shape of the distribution.

Munroe answered 21/8, 2018 at 21:30 Comment(0)
T
5

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)
Tabbie answered 21/8, 2018 at 22:27 Comment(0)
P
6

Well, if you sample a number from weibull distribution with scale parameter missing (which assumes scale is equal to 1), then to get it scale multiply by lambda.

x = numpy.random.weibull(a)
return lambda*x
Platto answered 21/8, 2018 at 21:51 Comment(0)
T
5

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)
Tabbie answered 21/8, 2018 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.