Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 831
Jack Karrde Avatar asked May 04 '20 13:05

Jack Karrde


1 Answers

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])
like image 136
linog Avatar answered Sep 20 '22 17:09

linog