Home > OS >  Generate random numbers from a normal distribution
Generate random numbers from a normal distribution

Time:03-23

I couldn't create normal distribution with python. I tried this but not worked exactly.

def prove_nd(num,mean=3,std_dev=1.25):
n= np.random.normal(mean,std_dev,num)

print(n)

prove_nd(3)

image

CodePudding user response:

Could you provide the error message or more details about how it is not working?

Because your code runs without any problems, maybe you forgot to write import numpy as np?

import numpy as np

def prove_nd(num, mean=3, std_dev=1.25):
    n = np.random.normal((mean, std_dev, num))
    print(n)

prove_nd(3)

The above code gives this output:

[4.22306108 2.31908355 3.39390751]
  • Related