An Analog to Rnorm in Python

An Analog to Rnorm in Python

Good morning!

I am looking to create an analog of some code in R

Basically, I have a function that, among other things, takes a seed provided by the user (default is NULL), along with a specific distribution (default is rnorm), and outputs 9 random numbers, saved as a vector "e". This is what it looked like in R...

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

...other code...

e <- dist(9,...)

Now I'm converting the function to Python, but I can't quite seem to find an analog that would work, where a user can replace the base seed and distribution.

Here's what i have so far...

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

...other code...

e = dist(9)

1 Answer

See numpy.random.normal function (doc here)

For instance:

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])
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.