I was programming a method that applied statistical bootstrapping over a sample in python, and I have come with two solutions, one which is fully vectorized, and other that uses list comprehension.
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
sample = np.array([80,75,91,97,88,77,94])
bs_sample_1 = np.random.choice(sample,size = (10000,7)).mean(axis = 1)
bs_sample_2 = np.array([np.random.choice(sample,size = 7).mean() for i in range(10000)])
plt.figure()
sns.distplot(sample)
plt.figure()
sns.distplot(bs_sample_1)
plt.figure()
sns.distplot(bs_sample_2)
I don't have much knowledge about RNG, but I not sure if the two operations are equally valid to generate bootstrap samples.
Aucun commentaire:
Enregistrer un commentaire