An analog to rnorm in python
Asked Answered
L

1

6

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)
Luane answered 4/5, 2020 at 13:26 Comment(0)
N
10

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])
Naturalism answered 4/5, 2020 at 13:28 Comment(1)
i sometimes get lost with the new np updates.. or is it this one ?numpy.org/doc/stable/reference/random/generated/…Stereopticon

© 2022 - 2024 — McMap. All rights reserved.