dimanche 31 mars 2019

Difference between these two methods to generate number

I'm a beginner on python. Here is the problem I need to solve:

Generate 10000 random numbers by uniform distribution. Randomly select 10 numbers from these 10000 numbers 20 times. Compute the sample mean and sample standard deviation.

I found that there are two ways to generate 10000 numbers by uniform distribution.

The first one is

import numpy as np
x = np.random.uniform(0,1,10000)

sample1 = []

for i in range(20):
    s1 = np.random.choice(a = x, size = 10, replace = True)
    m1 = np.mean(s1)
    sample1.append(m1)

smean1 = np.mean(sample1)
sstd1 = np.std(sample1)

The second one is

import numpy as np
x = np.random.random_sample((10000,))

sample1 = []

for i in range(20):
    s1 = np.random.choice(a = x, size = 10, replace = True)
    m1 = np.mean(s1)
    sample1.append(m1)

smean1 = np.mean(sample1)
sstd1 = np.std(sample1)

I don't know what's the difference between these two.




Aucun commentaire:

Enregistrer un commentaire