-1

I'm trying to generate a random sample with scipy .rvs method. However I have to limit the decimal places of each value sampled to, for example, 4.

As an example:

n=1000
X_list=[]
for i in range(n):
    X = laplace_asymmetric.rvs(loc=1, scale=0.06301609, kappa=0.69327604)*HB
    X_list.append(X)
  • 1
    Side note: you can use the `size=` argument to `rvs()` to generate multiple numbers at once. This is faster than using a loop. – Nick ODell Apr 09 '23 at 22:45

1 Answers1

2

I don't know about a built-in solution in scipy, but if you don't mind rounding your generated values, you could use the round function to just adjust your values once they are generated:

n=1000
X_list=[]
# define number of decimal places you want to use
dec_places = 4
for i in range(n):
    X = laplace_asymmetric.rvs(loc=1, scale=0.06301609, kappa=0.69327604)
    X_list.append(round(X, dec_places))
mcvincekova
  • 161
  • 5