python 中 rnorm 的模拟

Jac*_*rde 4 python r function distribution normal-distribution

早上好!

我正在寻找在 R 中创建一些代码的模拟

基本上,我有一个函数,除其他外,它采用用户提供的种子(默认为 NULL)以及特定分布(默认为 rnorm),并输出 9 个随机数,保存为向量“e”。这就是它在 R 中的样子...

function (...other variables..., seed=NULL, dist=rnorm)

...other code...

e <- dist(9,...)

Run Code Online (Sandbox Code Playgroud)

现在我正在将函数转换为 Python,但我似乎无法找到一个可以工作的模拟,用户可以在其中替换基本种子和分发。

这是我到目前为止...

def (...other variables..., seed=None, dist=?):

...other code...

e = dist(9)
Run Code Online (Sandbox Code Playgroud)

lin*_*nog 5

请参阅numpy.random.normal功能(此处为文档

例如:

import numpy as np
np.random.normal(0,1,9)
array([ 0.33593283, -0.18149502,  0.43148566,  1.46831794, -0.72244867,
       -1.40048855,  0.52366471,  0.34099135,  0.71654992])
Run Code Online (Sandbox Code Playgroud)