0

I would like to create a function that will take the probability distribution and the list or array of parameters (in order) and return a random variable of this distribution and parameters. If I know that the distribution has two input parameters, for instance, then the following function will return what I wish.

def rv(dist, paras):
  return dist(paras[0], paras[1])

For example, for a standard normal variable we have

In [1]:  import numpy as np

In [2]:  rv(np.random.normal, [0,1])

Out[2]:  -0.2985108994386439
         

However, I would like to extend this to a more general case, where the number of parameters can be arbitrary. Can someone offer me guidance on how to do this?

  • 2
    I mean... does just `return dist(*paras)` work for you? The `*` operator unpacks `paras` into separate arguments. – AKX Apr 04 '22 at 12:10
  • 1
    More precisely, `def rv(dist, *args): return dist(*args)`, but at this point you could call `dist` yourself – Alexey S. Larionov Apr 04 '22 at 12:12

0 Answers0