给定分布和参数列表或数组生成随机变量

发布于 2025-01-18 20:34:16 字数 375 浏览 0 评论 0原文

我想创建一个函数,它将采用概率分布和参数列表或数组(按顺序)并返回该分布和参数的随机变量。例如,如果我知道分布有两个输入参数,那么以下函数将返回我想要的结果。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文