给定分布和参数列表或数组生成随机变量
我想创建一个函数,它将采用概率分布和参数列表或数组(按顺序)并返回该分布和参数的随机变量。例如,如果我知道分布有两个输入参数,那么以下函数将返回我想要的结果。
def rv(dist, paras):
return dist(paras[0], paras[1])
例如,对于标准正态变量,我们有
In [1]: import numpy as np
In [2]: rv(np.random.normal, [0,1])
Out[2]: -0.2985108994386439
但是,我想将其扩展到更一般的情况,其中参数的数量可以是任意的。有人可以指导我如何做到这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论