jeudi 18 mars 2021

Why am I getting different bootstrap results using different algorithms

I am using two different methods of trying to generate a bootstrap sample

np.random.seed(335)
y=np.random.normal(0,1,5)
b=np.empty(len(y)) #initializes an empty vector
for j in range(len(y)):
    a = np.random.randint(1,len(y)) #Draws a random integer from 1 to n, where n is our sample size
    b[j] = y[a-1] #indicies in python start at zero, the worst part of Python in my opinion
c = np.random.choice(y, size=5)
print(b)
print(c)

and for my output I get different results

[1.04749432 1.71963433 1.71963433 1.71963433 1.71963433]
[-0.25224454 -0.25224454  0.46604474  1.71963433  0.46604474]

I think the answer has something to do with the random number generator, but I'm confused as to the exact reason.




Aucun commentaire:

Enregistrer un commentaire